Using command blocks, how can I make the person that touched the command block's button get teleported, not the person closest to the command block?
2 Answers
This is impossible. The closest you can get is by specifying that it should teleport the player closest to the button, like this:
/tp @p[x=buttonX,y=buttonY,z=buttonZ] newLocationX newLocationY newLocationZ
e.g.:
/tp @p[x=420,y=42,z=-1337] 1024 37 2000001
The thing about command blocks is that they are operated by redstone signals, which can vary from circuts as small as a single button to circuts as huge and sprawling as mob farms to complex circuts like self-powered timers. Redstone signals do not carry identity (they may not even have it), so there isn't a way to tell who pushed a button.
The Guy With the Hat's answer is good to use - teleport the player closest to the structure. You will likely get more perfect mileage if you use a pressure plate on top of the block instead of a button, and then you can use a radius limiter on the @p (I think it's r=1
or whatever other number) to ensure that some random player won't get teleported when a mob presses the button.