How to Teleport Players When They Enter a Certain Area/Coordinates
I am trying to teleport a player to certain coordinates once they enter an area.
The idea is that they walk into a really small building, but once they turn a corner, they get teleported into a larger building.
Please refer to the adventure map named '5 Cubed', if you need help understanding what I am asking.
34 Answers
1.9 Solution
Place the following command in a repeating command block set to always active:
/execute @a[x=a,y=b,z=c,r=d] ~ ~ ~ tp @p e f gWhere:
a,b, andcare the XYZ co-ordinates that you want to teleport players fromdis the radius in blocks around that point where players will be selected (min 1)e,f, andgare the XYZ co-ordinates that you want to teleport players to (i.e. the destination)
1.8 Solution
Use the same command as above, but since no repeating command blocks exist, place the command block on a fill clock.
31.13.x solution
If anyone is coming from 1.13.x, the /testfor command has been deleted. In that case if you want to teleport someone you can use the /execute command as thus
/execute if entity @a[x=0,y=0,z=0,distance=..1] run tp @p x y zThe first set of X Y Z coordinates is where you want the player to be teleported from, the second is where you want the player to be teleported to.
Put pressure plates around your desired area. under each pressure plate place a command block that will teleport you to coordinates of your choice. do this by inserting the command /tp @p x y z into your command block.
It's actually quite easy:
Just have a command block that is on a clock, and it should constantly testfor a player at certain co-ords:
/testfor @a[x=???,y=???,z=???](copy exactly except replace ? with the co-ords) then put a comparater leading out of it to a command block that:
/tp @p ??? ??? ??? (x,y,z).You can also do:
/test for @a[x=???,y=???,z=???,r=?] Where r is a radius (i.e. if r is 3 it will test for players within 3 blocks in a directions of the co-ords specified.
1