Minecraft – Is There a Way to tp a player back to Spawn After Falling into Void

minecraft-commandsminecraft-java-edition

I am making a mini-game for my server and would like the lobby to be a skyisland over the void, my question is, Is there a way to tp a player back to the skyisland if they fall in the void? I have a vanilla server and don't want to use plugins or mods if possible.(maybe a command?)

Best Answer

For a world-wide area, can use /execute to change the coordinate origin to that of the player, and teleport them when they reach below y=0 (going downwards by 64 blocks):

/execute @a ~ ~ ~ /tp @a[c=1,y=-1,dy=-64] X Y Z

Or:

/execute @a ~ -1 ~ /tp @a[c=1,dy=-64] X Y Z