How do I make a timer, and then test if it reaches zero?
I'm making a simple PvP Arena, and the plan is this: When the game starts, give the players all their gear, teleport them from the lobby to the battle arena and start a countdown timer (in my case, it'll be 5 minutes long); when the countdown timer reaches 0, teleport them back to the lobby and clear their inventories.
I got everything else down, but I'm stuck on the part where I need to implement a timer. So far, I made a dummy objective called Timer and have a hopper clock subtracting 1 of this objective from a non-existent player called Time. How do I go about displaying this time on screen via /title
, and triggering the teleportation after it reaches 0?
This is in version 1.15.2.
To display the time:
/title @a actionbar [{"text":"Time left: "},{"score":{"objective":"Timer","name":"Time"}}]
and to detect when the timer reaches a specific value:
/execute if score Time Timer matches 0 run <command_to_run>