I am a little confused with the execute command in command blocks. I have a server with Essentials and Worldedit plugins 1.17 and I want to activate command blocks by going near it as a jumpscare.

I have researched alot of commands and it seems that the command block considers it valid but it doesn't work when an entity is near it. I have tested a couple of commands and it seems like it doesn't work. For example: /minecraft:execute if entity @p[distance=..5] run time set day

Is there any alternative for this if ever it doesn't work? Because redstone requires too much work and my main goal is to activate jumpscares that won't be noticeable. Thank you!

  • What commands have you tried so far? It is easier to fix a specific problem instead of rewriting the whole code.
    – dly
    Commented Aug 17, 2021 at 6:18
  • I have used /minecraft:execute if entity @p[distance=..5] run time set day
    – ChinoQT
    Commented Aug 17, 2021 at 6:44
  • I also used adding coordinates to the @p but it doesn't work
    – ChinoQT
    Commented Aug 17, 2021 at 6:44
  • I have found the solution, but is there anyway to not SPAM? I managed to make it work but it is spamming the command of playsound
    – ChinoQT
    Commented Aug 17, 2021 at 6:51
  • You should edit your question accordingly, otherwise we don't know what you did. :)
    – dly
    Commented Aug 17, 2021 at 6:54

1 Answer 1


There are multiple ways to do this, my favorite is to test for players that are close to the specific area and then use another command to deactivate the first command block.

The first command would be:

/execute as @a[x=-43,y=56,z=90,distance=..2] run time set day

and the next one would look like this:

execute as @a[x=-43,y=56,z=90,distance=..2] run setblock x y z air

These commands test for the same but the second removes a Redstone block to deactivate the command blocks:

enter image description here

The repeating command block is set to Needs Redstone so it only works when the Redstone block is next to it.

This however makes it so it only works once until you place the Redstone block back.

You can instead use scoreboards to make it work on all players but still only once:

First, you need to add the scoreboard:

/scoreboard objectives add JumpScare dummy

Then the first command block:

execute as @a[x=-53,y=56,z=91,distance=..2] run scoreboard players add @s JumpScare 1

This will add a score of 1 to the scoreboard JumpScare to one player.

And the second command block will do the jumpscare part:

execute as @a[x=-53,y=56,z=91,distance=..2] if score @s JumpScare matches 1 run time set day

This command tests for when a player has a score of 1 on the scoreboard JumpScare and then sets the time to day.

Here the repeating command block is set to Always Active so no need for an external Redstone block. You could still make it need the Redstone block if you'd like to manually deactivate the whole thing.

If you would then need to reset the players score for the jump scare to work you would use any of these commands:

/scoreboard players set "Player" JumpScare 0

/scoreboard players reset "Player" JumpScare

You can use as @a[] instead of if entity @p[] if you specify the coordinates.

Within the selector, you need to add x, y, z, as well as distance=.. or dx dy dz. This way you can specify specific areas:

execute as @a[x=0,y=65=z=0,dx=1,dy=1,dz=1]

This will target all players in a cube from 0 65 0 to 1 66 1.

The dx dy dz acts like distance but adds specifically to the coordinate you specify. Also works with negative numbers.

distance will detect any player in a sphere area.

This command will detect any player within 2 blocks from 0 65 0 in any direction:

execute as @a[x=0,y=65,x=0,distance=..2]

Using this you don't need to have the player walk up to a command block, you could instead place something like a nonmoving mob and just specify the coordinates in the command.

Using the as @a[] will also make you able to use the @s later in the command, as I did in the scoreboard test.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .