Minecraft – How to delay a command

minecraft-commandsminecraft-java-edition

I tried:

/tp @e[type=ArmorStand,T=100] ~ ~1 ~

Then:

/tp @e[type=ArmorStand,Time=100] ~ ~1 ~

I'm stuck.

I am looking for a command-block only solution.

Best Answer

So you are trying to do @e[T=100] and @e[Time=100], but T and Time are not selector arguments, so I will be showing you how to make a custom timer argument.


This solution only works on Minecraft 1.9 and above!

This is possible with scoreboard objectives. You will have to do the following for each command you want to delay. Note that this also only works on commands executed on entities.


How to make:

  1. Create a scoreboard objective to hold delays (I will use time as an example)

    /scoreboard objectives add time dummy
    
  2. Create a command block arrangement like this: Repeating > Chain > Conditional Chain

  3. Place the following commands into each command block:

    • Repeat Command Block:

      /scoreboard players add @e[score_time_min=1] time 1
      
    • Chain Command Block 1: Put your delayed command here. For example:

      /tp @e[type=ArmorStand,score_time_min={delay}] ~ ~1 ~
      
    • Chain Command Block 2:

      /scoreboard players set @e[score_time_min={delay}] time 0
      
  4. Start the delay by running this command:

    /scoreboard players set {entity} time 1
    

A few things to note:

  • Replace {delay} with the delay you want in ticks, plus one. For example, if you want a delay of 5 seconds, you would put 101 there since 5sec * 20 tick/sec + 1 = 101.
  • Replace {entity} with the selector for the entity that you want to run the command. For example, @e[type=ArmorStand,name=Bob].
  • The command in the second command block is up to you to. Just know that your need to run the command with {entity} targeted and you must have score_time_min={delay} in the entity selector for that command.

If you want a full example, here are the commands for the command blocks to teleport an ArmorStand by the name of "Bob" 5 blocks in the air 5 seconds after running the start delay command (step #4 above):

/scoreboard players add @e[score_time_min=1] time 1
/tp @e[type=ArmorStand,name=Bob,score_time_min=101] ~ ~1 ~
/scoreboard players set @e[score_time_min=101] time 0

Feel free to comment on this post with any questions! Ill try to answer them as soon as possible!

For additional information on how to format target selectors and arguments, see the Minecraft Wiki.