Updated:
Run these once
/gamerule keep_inventory true
/gamerule immediate_respawn true
/gamerule fall_damage false
/scoreboard objectives add time dummy "Time"
Players keep their items, respawn instantly and take no fall damage. The last line makes a score for the timer. These names are for Java 1.21.11+. On 1.21.10 and earlier, and on Bedrock, use keepInventory, doImmediateRespawn and fallDamage (gamerule list).
Start pad
Put a pressure plate at the start with a command block (Impulse, Needs Redstone) directly under it. Stepping on the plate runs it once. Chain command blocks run the extra lines.
/gamemode adventure @p
/spawnpoint @p ~ ~1 ~
/tag @p add running
/scoreboard players set @p time 0
Adventure mode stops players breaking the course. ~ ~1 ~ is one block above the command block, where the plate is. See command block tutorial for block types.
Checkpoints
/spawnpoint @p ~ ~1 ~
Put a plate and command block on each checkpoint platform. The last one a player stepped on becomes their respawn point.
Send fallen players back
Fill the area under the course with water, and put this in a repeating command block (Always Active):
/execute as @a[tag=running] at @s if block ~ ~ ~ minecraft:water run kill @s
A player who touches the water respawns at their last checkpoint, with no death screen and no lost items thanks to the rules above. Over the void, check height instead:
/execute as @a[tag=running] at @s if entity @s[y=-64,dy=40] run kill @s
This catches anyone between Y -64 and -24. Change the numbers to suit your course.
Timer
/scoreboard players add @a[tag=running] time 1
In a repeating command block this adds 20 per second. Run /scoreboard objectives setdisplay sidebar time once to show it on the right of the screen.
Finish
/tag @p remove running
/title @p title {"text":"Finished!","color":"gold"}
/tellraw @a [{"selector":"@p"},{"text":" finished! Time: "},{"score":{"name":"@p","objective":"time"}},{"text":" (20 = 1 second)"}]
/gamemode survival @p
Chain these under the finish plate. Removing the running tag stops the timer and the fall check. More on text in the title and tellraw guide.
When it does not work
- The plate does nothing: check the block is Impulse and Needs Redstone, and the plate is right on top.
- The wrong player is picked:
@pis the player nearest the command block, which is whoever stands on the plate. - Fallen players stay put: check the repeating block is Always Active and that the start pad added the
runningtag. - Chat fills with command output: run
/gamerule commandBlockOutput false(minecraft:command_block_outputon 1.21.11+).
Check your command
The Command Error Doctor checks common syntax mistakes in your browser.