How do I set up a delay within a command block

I’m trying to recreate Runner in Minecraft 1.9 singleplayer, but I cannot get how to set up a delay so that the player can run without getting killed.

  • How to assign players in MC to a scoreboard team automatically when they join?
  • How to prevent water from freezing
  • How do you spawn ONLY zombies in Singleplayer?
  • How can I easily get a lot of Iron?
  • How to add custom sounds in a resource pack?
  • Minecraft Vanilla 1.9 crash with problematic frame ig8icd64.dll
  • How do I target players found by /testfor?
  • Cannot launch Minecraft: CertificateNotYetValidException
  • How to make a block disappear after a certain period of time
  • How can I improve the performance of Minecraft?
  • How can I access my copy of Minecraft from a new Xbox account?
  • Minecraft crashes after logging in: A fatal error has been detected by the Java Runtime Environment
  • 2 Solutions collect form web for “How do I set up a delay within a command block”

    Add an scoreboard objective:
    /scoreboard objectives add Moving stat.walkOneCm

    Run the following commands in a clock(in exactly that order):

    /kill @a[score_Moving=0,m=!1]
    /scoreboard players set @a Moving 0
    

    Warning:
    Be careful when setting this up.
    You will get killed, when not walking/running.
    And when the machine is killing you the whole time, you have no chance to disable it(except for external tools).

    I think what you want is a “grace period” for not running? I.e. the command blocks kill you if you stand still for more than, say, a second?

    If so, you can run these in a repeat/chain setup:

    /scoreboard players set @a OnGround 0 {OnGround:0b}
    /scoreboard players set @a OnGround 1 {OnGround:1b}
    /scoreboard players remove @a[score_Moving_min=1] Moving 1
    /scoreboard players set @a[score_Moving_min=20] Moving 20
    /kill @a[score_Moving=0,score_OnGround_min=1,tag=Running]
    /scoreboard players tag @a[score_Moving=0,score_OnGround_min=1,tag=Running] remove Running
    

    Moving is a stat.walkOneCm type objective, the OnGround tag is dummy. Moving does not increase while jumping/falling, which makes this addition necessary or else jumping or falling could kill you. The Running tag is to prevent an endless kill loop, add it to anyone that has to run to not die.

    To adjust the timing, adjust the score set in the second command (both in the target selector and the set command) to the number of ticks the player may stand still (20 ticks = 1 second). This command acts like a “hard cap” on the Moving score (it can never exceed the value given).

    We love Playing Games, especially Video Games.