I'm making a "floating piston", so when the player moves into a specific area, the dirt acts as an activator of a circuit.

How can I make the execute (wired up to a pulse clock) work inside a range, and/or coordinates, as in execute @p[x=~10,y=~,z=~15,r=5] ~ ~ ~ setblock 400 15 400 dirt I would have 4 command block, one for each colour.

I did this earlier with /testfor @p[r=3] , a pulsar per commandblock, and a comparator+repeater, just beneath where it was supposed to go, but I figured it would look neater if I moved all the command blocks away from the gamezone itself, because there were little space. Easier to troubleshoot and edit aswell.

It did work for execute @p ~ ~ ~ setblock 400 15 400 dirt , but as soon as I add dataValues to the player, the UUID fails, saying the expresion is wrong.

I might use scoreboards to do some stuff aswell, but it's a bit messy yet, so I prefer avoiding using them yet.

The purpose of the game is making a Stadium where you select your "color" (which will all give you different benefits), on each side of the stadium. When you are finished choosing your color, you get into the arena, and you fight against the other player (with the same color-selecting, just on the opposite side of the arena).

Color-selection, where the middle zone, currently red(wool), shows the present selected color

I could do it with buttons, but hey, it looks cooler with just moving over the coloured glass.

Thanks in advance.

  • Have you made an attempt to make this work yourself? Arqade works better when you show what you've tried, and where you're stuck. In return, answers are specific to your situation, and exactly what you're stuck on. You get a better answer, Arqade gets a better question. Everybody wins!
    – Frank
    Commented Apr 8, 2015 at 21:41
  • You could always try pulsing /testfor @p[r=1,x,y,z] command at the co-ordinates of the coloured blocks, so when a player walks over, it triggers an redstone comparitors which then triggers other blocks connected to its circuit.
    – aytimothy
    Commented Apr 9, 2015 at 2:41
  • Redstone comparators don't mix well with multiplayer compatibility. Though scoreboard may be a little hard to learn, it works much, much better than comparators.
    – Moddl
    Commented Apr 9, 2015 at 4:08
  • Parameters in the target selectors do not accept the tilde notation. You must specify a location Commented May 26, 2015 at 23:31

3 Answers 3


I have two possible solutions for you.

First Solution

If you are trying to select a player using the selector relative to where the player is located from a specific coordinate, the selector code doesn't except the '~' character like many commands do to communicate relative coordinates. Instead use dx, dy, & dz. As an example, using the numbers from your execute command

execute @p[x=X,y=Y,z=Z,dx=10,dy=0,dz=15] ~ ~ ~ setblock 400 15 400 dirt 0 replace

This will select a player remotely, as you described above, if your command block is far away (within 16 loaded chunks I believe), and will set up a "volume" or a "box" that is x=~10, dy=~0, and dz=~15 that has an origin (starting corner) at the specific coordinate x=X, y=Y, & z=Z, where X, Y, & Z are positive or negative integers: decimal numbers are not excepted.

As long as the location/zone where the player needs to be detected isn't moving to some other location in the world, this should work just fine.

Second Solution

If the player walking over blue stained glass, for example, could be used to trigger your event instead, here's how you might accomplish that.

execute @a ~ ~ ~ detect ~ ~-1 ~ minecraft:stained_glass 11 setblock 400 15 400 dirt 0 replace

The documentation from the official minecraft wiki looks like this

execute <entity> <x> <y> <z> detect <x2> <y2> <z2> <block> <data> <command …>

where <data> is where you would enter the data value of the color of glass you wish to use to trigger a specific event (11 being blue). <x2> <y2> <z2> are just the coordinates of the block you'd like to detect. In the example I used ~ ~-1 ~ which just detects for a blue stained glass block below all players (which the all players @a selector can be replaced with whatever selector you happen find best to use).

Hopefully this helps.

As a Warning

Based on what I have read from the wiki, it may cause the execute command to fail if a player who does not have permission to execute the specified command is selected. Which means, if your players are meant to be in survival or adventure mode, you may have to use the execute command on an invisible entity (such as an armor stand with NBT tags set to {Marker:1,Inivisible:1}) to detect whether a player has entered the specified area, and then trigger the event that way.

  • Thank you, that should fix it. I will try both methods once I get onto my server again (personal reasons, won't connect in some time xD)
    – mazunki
    Commented Apr 10, 2015 at 10:53

you can do this with /testfor @a[x=X,y=Y,z=-Z,r=R]

XYZ and are coordinates and R is the radius.
Just put the command in a commandblock and update it frequently using redstone. A Comparator that has ben put at the commandblock will be activated if the statement is true and deactived if its false.


how about /testfor @p[x=~0,y=~0,z=~10,r=3] to test for a player 10 blocks away from the command block.

  • 1
    You cannot use relative coordinates in selectors
    – Skylinerw
    Commented Dec 8, 2017 at 15:38
  • then how would i do it?
    – Jexll Wuff
    Commented Dec 12, 2017 at 17:45
  • with absolute values Commented Jan 18, 2018 at 21:54

You must log in to answer this question.

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