Updated:
The basic shape
/execute as @a at @s if block ~ ~-1 ~ minecraft:gold_block run effect give @s minecraft:speed 1 1
| Part | Meaning |
|---|---|
as @a | Run as each player |
at @s | Run at that player's position |
if block ~ ~-1 ~ gold_block | Continue only if the block below is gold |
run … | The command to run |
This gives Speed to anyone standing on a gold block.
Mistake 1: no run
/execute as @a at @s say hello is an error; the command must follow run. On Java, an execute that ends with a condition and no run just reports "Test passed" or "Test failed", which is handy for checking a condition.
Mistake 2: expecting as to move the position
as changes only the runner. In a command block, /execute as @a run setblock ~ ~-1 ~ stone places stone under the block again and again, not under each player.
| Form | Runner | Position |
|---|---|---|
as @a run | Each player | Unchanged |
at @a run | Unchanged | Each player |
as @a at @s run | Each player | Each player |
More in execute as vs at.
Mistake 3: old Bedrock syntax
Bedrock switched to the Java-style syntax in 1.19.50. Old commands like /execute @a ~ ~ ~ detect ~ ~-1 ~ gold_block 0 effect @s speed need rewriting:
/execute as @a at @s if block ~ ~-1 ~ gold_block run effect @s speed 1 1
Mistake 4: conditions
if entitychecks whether at least one target exists;if blockchecks the block at a position.- Scores:
if score @s money matches 100...100..is 100 or more,..9is 9 or less,10..20is between. - Use
unlessfor "not":unless entity @e[type=zombie]continues when no zombie exists.
No error, but nothing happens
If as selects nobody, execute stops silently. Test one step at a time:
# 1. Is anyone selected?
/execute as @a at @s run say selected
# 2. Add the condition
/execute as @a at @s if block ~ ~-1 ~ minecraft:gold_block run say condition true
If a name appears in chat, everything up to that point works. See target selectors when nobody is found.
Common questions
- run execute …? It works but is unnecessary; chain as many subcommands as you need before
run. - @p or @s after as?
@s.@ppicks whoever is nearest, which may be someone else. - Save a result to a score? On Java:
execute store result score @s objective run ….
Check your command
The Command Error Doctor checks common syntax mistakes in your browser.