How do I teleport someone who enters a specific tunnel on Minecraft 1.17.1?

I am making a map on Minecraft 1.17.1 and I'm tying to make a challenge where you need to go through the correct tunnel, if you go through the wrong one you'll get teleported to the start.

I don't know how to do it, so I "tried" using the execute command but I don't know how to really use it.


Solution 1:

This can be easily achieved with a command block and the tp command:

tp @p[distance=..4] x y z

Where x, y, and z are the respective coordinates of your starting position.


Give yourself a command block with:

give @s command_block

Place it where it can be concealed (e.g. under a block in the tunnel) and set it's configuration to:

  • Block Type: Repeat
  • Condition: Unconditional
  • Redstone: Always Active
  • Command Input: tp @p[distance=..4] x y z
    • Where x, y, and z are the respective coordinates of your starting position.