I found 11 questions like this on gamingSE already, but none of them have proper and up-to-date answers. So I'm creating this Q&A:

How do you either activate a command x seconds/minutes/hours/… in the future or every x seconds/minutes/… in a loop?

Repeating command blocks and ticking functions execute 20 times per second, redstone is not a good solution in many situations and most of the extremely fancy solutions, like falling blocks in cobwebs, have broken over time or are needlessly complicated.

  • 1
    Why is redstone not a good solution in many situations? – John Feb 6 at 20:36
  • @John Good question. I've added a link to the answer to my post. – Fabian Röling Feb 7 at 11:05
  • Actually, it does a somewhat bad job of stating why it's evil in the first place. I'll add an answer there one day. For now, in short: Lag, slower, might be tampered with, unsafe (water etc.), chunk loading, bugs, less features (like execution context), … All of those are issues you get with redstone. – Fabian Röling Feb 7 at 11:09

For functions there is a built-in way to do this:

/schedule function <function_name> <time>

So if you for example want to execute the function named "test" in the namespace "abc" in 1 hour, which equals 3 in-game days, you can use any of these commands:

/schedule function abc:test 3d
/schedule function abc:test 3600s
/schedule function abc:test 72000t
/schedule function abc:test 72000
/schedule function abc:test 3d replace

Unit postfixes for minutes, hours etc. do not exist. The in-game days unit is not affected by sleeping or /time.

If you have changed your mind, you can abort a scheduled function execution like this:

/schedule clear abc:test

If you want to schedule multiple executions, you can use append instead of replace. If you want to replace all existing schedules of this function with the current one, you can use replace or just provide no mode at all, replace is the default.

To loop execution, you can simply use the /schedule command at the end of your function. Usually you'll want to do this under some condition, so that it doesn't keep looping forever.

If you cannot or do not want to use functions or /schedule, you can still use the old scoreboard timer method. This needs a little bit more resources, because it actively does something every tick, but it shouldn't cause noticeable lag.

As a preparation, you need a scoreboard:

/scoreboard objectives add timer dummy

The "dummy" type is one that is not affected by anything except commands.

In a repeating command block or ticked function, execute this command:

scoreboard players add $timer timer 1

The name "$timer" cannot possibly be a real player name, so it is a good choice for a dummy player name. If you do not want it to show up in a scoreboard sidebar display, start the name with a # character.

Now you can do something once the timer reaches your desired number of ticks like this:

execute if score $timer timer matches 100 run say 5 seconds are over!

If you want to do something repeatedly after 5 seconds, simply replace 100 with 100... If you want a variable starting time, compared to someone else's score, you can for example use >= @p points instead of matches 100.

If you want to repeat something every x seconds/minutes/…, you can just reset the timer after you have done whatever you want to do with it. So at the end of your command block chain or ticked function, you put this:

execute if score $timer timer matches 100 run scoreboard players set $timer timer 0

This concept can also be used to do something every x times something happens. To do this, simply increase the timer only conditionally instead of every tick, for example like this:

execute if block ~ ~1 ~ stone run scoreboard players add $timer timer 1

But make sure to change whatever the command is checking for directly afterwards, otherwise it keeps ticking up by 1 every tick as long as the condition is matched.

  • If you want to make your delay longer than 4294967296 ticks (almost 7 years) for some reason, you either need to make a more complex command setup, like ticking up a second timer every time the first one resets, or, for the most extreme case, use a universe death clock. SethBling also has some fun compact timers that last a REALLY long time here and here. – Fabian Röling Feb 4 at 10:29
  • You could make a mini-game out of this - set a timer to limit the length of your world. Once you reach that timer, you are killed indefinitely, making the game unplayable. – Ben Feb 5 at 0:17
  • You can do literally everything with this that requires timers or delays. – Fabian Röling Feb 5 at 23:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.