How can I teleport every entity below Y=0 to Y=255 in Minecraft?

How can I teleport every entity below Y=0 to Y=255 in Minecraft? I'm making Skyblock, but I want falling out of the void to teleport you to the height limit.


Solution 1:

This is taken from this post (archive).

You can store all the player's y-level in a scoreboard:

/scorebaord objectives add dummy y

Then set the scoreboard values to the players' y-level (put this in a repeating command block):

execute as @a store result score @s y run data get entity @s Pos[1]

Finally, put this in another repeating command block to teleport the players to the height limit:

execute as @a[scores={y=..0}] at @s run tp @s ~ 255 ~