Updated:
1. The basic form
execute store result score <targets> <objective> run <command>
execute store success score <targets> <objective> run <command>
result saves the number the command returns. success saves 1 if it worked and 0 if it failed. Besides score you can store into entity, block, storage and bossbar.
2. Setup
/scoreboard objectives add count dummy
/scoreboard objectives add y dummy
/scoreboard objectives add hp dummy
3. Count players
execute store result score #players count if entity @a[gamemode=adventure]
Ending with if entity stores how many entities matched. Use it to count players still in a minigame.
4. Save position and health
execute as @a store result score @s y run data get entity @s Pos[1]
execute as @a store result score @s hp run data get entity @s Health
Decimals are dropped, so Y 64.5 becomes 64. See the data command for paths.
5. Save the day and time
execute store result score #day count run time query minecraft:day repetitions
execute store result score #time count run time query minecraft:day
This is the Java 26.1+ form; on 1.21.11 and older use time query day and time query daytime. See the day counter and clock to show them.
6. Write a score to a bossbar or mob
execute store result bossbar minecraft:timer value run scoreboard players get #time count
execute store result entity @e[type=zombie,tag=boss,limit=1] Health float 1 run scoreboard players get #hp count
The first line fills a bossbar. float 1 means store as a decimal, multiplied by 1.
7. Branch on success
execute as @a store success score @s count run clear @s minecraft:diamond 1
execute as @a[scores={count=1}] run give @s minecraft:golden_apple
A tiny shop: only players who paid one diamond get the apple.
Troubleshooting
- Player data does not change:
store result entitycannot edit players. Store into a score or a mob. - Decimals vanish: scores are whole numbers. Add a scale such as
Pos[1] 10to keep one decimal. - Bedrock: there is no execute store. To count players, reset a score and add 1 with
execute as @a.
Check your command
The Command Error Doctor checks common syntax mistakes in your browser.