1

I am trying to teleport all players who go to the Y level 8, but this command teleports all players from Y level 8 and the command block coordinates:

/execute if entity @a[y=8,distance=..10] run tp @s ~ ~100 ~

How do I make it so if someone goes to Y level 8 they teleport to safety? I already know how to teleport players at specific coordinates, but I don't know how to do this.

2
  • I have not figured it out, but a short cut is putting a weird block below and when the block below them is that block, then they get teleported. execute at @a if block ~ ~-1 ~ minecraft:grass_block run tp @p 273 20 -70 0 37
    – Wookiee
    Commented Apr 19, 2022 at 0:38
  • 5
    Possible duplicate of How do I target players with only a certain X, Y, or Z coordinate?
    – pppery
    Commented Apr 20, 2022 at 1:44

1 Answer 1

3

Note: this answer is simply for teleporting the player up 100 blocks after they reach y=8. It does not necessarily teleport the player to safety.

/execute as @a at @s if entity @s[y=8,distance=..10] run tp @s ~ ~100 ~.

You're close, but you need to use the at keyword to get the player's position rather than the command block's, and the as keyword to change the executor to the player.

The if then needs to be modified to use @s so it selects the correct person.

See documentation on the 'as' and 'at' keywords on the Minecraft wiki.

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