I'm currently making an adventure map and I want to know how to trigger Command Blocks when a player walks through a certain area. For example, if a player walks through a certain part of a cave, it would say "Don't go down there", or something. Or it could trigger a jump scare (but that's not what I'm looking for).

Specifically, I'm making it so that when the player walks through an area, it says "I think it would be a good idea to go exploring." in a first person perspective.


5 Answers 5


To test for a player in some distance from a certain place, use:

/testfor @a[x=X,y=Y,z=Z,r=R,rm=RM]

Where X, Y and Z are the middle coordinates of the area to test for a player, R and RM specify the minimum and maximum distances from the specified coordinates, respectively.

To run a command, eg. /say Hello when the testfor command returns true, place the @a[] part into an /execute command:

/execute @a[x=X,y=Y,z=Z,r=R,rm=RM] ~ ~ ~ /say Hello
  • I don't think it works, I probably did it wrong because I have no idea what your talking about as I'm not very good at command blocks, I only know simple commands. This is what I did: /testfor @a[x=-1,y=111,z=-11,r=4,rm=4] for the first command block and for the second: /execute @a[x=-1,y=111,z=-11,r=4,rm=4] ~ ~ ~ /say Hello Dec 9, 2016 at 19:01
  • Or if there was a way to make pressure plates invisible I would do that. Dec 9, 2016 at 19:04
  • @RezamatorYT the second value, rm is not inclusive - eg. r=4,rm=4 will never be true, but r=4,rm=5 should activate if something is in the specified distance. If no player is in the specified area, the command will act as if it was invalid.
    – user143228
    Dec 11, 2016 at 19:41

Spawn an invisible ArmorStand on that place, give it a Name:


summon ArmorStand ~ ~ ~ {Invisible:1,Invulnerable:1,CustomName:"sOp"}

Repeating command block: execute @e[type=ArmorStand,name=sOp] ~ ~ ~ execute @e[r=0] ~ ~ ~ tellraw @s {text:"I think it would be a good idea to go exploring.",color:green,bold:false}


You could put pressure plates down, then when stood on it could /say (Whatever) then you could use /setblock on whatever coordinates the pressure plate was to replace it with air.


This worked for me in version 1.14.4 of the Java Edition, on a repeating Command Block.
The command picks every value that's between x and dx - same with every other axis - and will show whatever message you want:

/msg @a[x=~,dx=~,y=~,dy=130,z=~,dz=~] (message here)


I think /msg @a[x=~,dx=~,y=~,dy=130,z=~,dz=~] (custom message here) is your best bet.

You must log in to answer this question.

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