Updated:
1. Setup (once)
/team add caller "Caller"
/team join caller Steve
/scoreboard objectives add walk minecraft.custom:minecraft.walk_one_cm
/scoreboard objectives add run minecraft.custom:minecraft.sprint_one_cm
/scoreboard objectives add phase dummy
walk and run count walked and sprinted distance on their own. phase remembers whether moving is allowed right now. See the team command.
2. Red light button
/scoreboard players reset @a walk
/scoreboard players reset @a run
/scoreboard players set #game phase 1
/title @a title {"text":"RED LIGHT","color":"red"}
An impulse block followed by chain blocks, wired to a button. Resetting the scores first means only movement after the call counts.
3. Send movers back (repeating)
/execute if score #game phase matches 1 as @a[team=!caller,scores={walk=1..}] run tp @s 0 64 0
/execute if score #game phase matches 1 as @a[team=!caller,scores={run=1..}] run tp @s 0 64 0
Put both in repeat blocks set to always active. Anyone who walks or runs even one centimeter after the call goes back to the start at 0 64 0. Change the position to fit your course.
4. Green light button
/scoreboard players set #game phase 0
/title @a actionbar {"text":"GREEN LIGHT","color":"green"}
The caller presses this when turning away again. While phase is 0, moving is safe.
5. Goal check
/execute as @a[team=!caller,x=0,y=64,z=40,dx=4,dy=3,dz=2] run tellraw @a [{"selector":"@s"},{"text":" reached the goal!","color":"gold"}]
See target selectors for areas.
6. Run it without a guard
/scoreboard objectives add dtimer dummy
# repeating block
scoreboard players add #game dtimer 1
# chain 1
execute if score #game dtimer matches 100 run title @a title {"text":"Red light!","color":"red"}
# chain 2
execute if score #game dtimer matches 110 run scoreboard players reset @a walk
# chain 3
execute if score #game dtimer matches 110 run scoreboard players reset @a run
# chain 4
execute if score #game dtimer matches 110 run scoreboard players set #game phase 1
# chain 5
execute if score #game dtimer matches 170.. run scoreboard players set #game phase 0
# chain 6
execute if score #game dtimer matches 170.. run scoreboard players set #game dtimer 0
At 20 ticks a second, players move for five seconds, then see Red light. Checks start half a second later so they can stop in time, and three seconds after that they can move again. Use the random command to vary the timing.
Troubleshooting
- Caught while still: the reset must run before phase is set to 1.
- Sneaking is not caught: add
minecraft.custom:minecraft.crouch_one_cmtoo. - Bedrock: there are no distance statistics, so this method does not work.
- Looking around: turning the camera adds no distance, so it is safe.
- No caller: switch the phase on a timer with the schedule command.
Check your command
The Command Error Doctor checks common syntax mistakes in your browser.