Minecraft – How to teleport players when they fall into a certain area in Minecraft

minecraft-commandsminecraft-java-edition

For an upcoming parkour event in our server, I wanted to do a system with command blocks in which if a player falls to a certain Y coordinate (e.g y=134), they get teleported back to the spawn. I've looked around and I've seen similar questions asked, however I can not get the commands to work + I need to cover an entire area, not just a block.

The specific coordinates I need people to be teleported back to the spawn are from 999909 136 999955 to 999897 136 999825.

Version is 1.16.5 on Java. All help appreciated.

Best Answer

I recommend setting up a command block as repeat, unconditional and always active and entering a tp command.

The key to covering only a certain area is using the target selector arguments, particularly the volume dimension arguments. Something like

tp @a[x=<value>, dx=<value>, y=<value>, dy=<value>, z=<value>, dz=<value>] <location>

... where...

  • The @a target selector targets all players
  • The <x>,<y>,<z> and <dx>,<dy>,<dz> selector arguments limit the @a selection only to a certain volume
  • The <location> is the x, y, and z coordinates of where you want the players teleported to

... will select all players, whose hitbox is at least partially contained in the volume defined by the start point [x, y, z] and the difference [dx, dy, dz] from the start point. Hence

@a[x=0, dx=10, y=0, dy=10, z=0, dz=10]

... will target all players in a cubic volume between the points [0, 0, 0] and [10, 10, 10].

If you define only the difference, the selector will select everyone in the volume starting from the coordinates of the entity executing the command (can be your command block).

So, in other words, in your case something like this should work:

tp @a[x=999909, y=136, z=999955, dx=12, dy=0, dz=130] <target x> <target y> <target z>