How to detect a player’s x coordinate and teleport them to the other side of the map in 1.15.2?
I have a Minecraft Earth map and I want it so if you go too far on one side, it will teleport you to the other side: so players can get from Japan to America by going through the Pacific Ocean. I tried the following command, but it didn't work. What should I do?
/execute as @e[x=5375,y=~,z=~,distance=..2] at @s run tp @s ~-10750 ~ ~
For my method, we will use scoreboards. First you must make a scoreboard with a dummy critera we'll name it xpos
. Then you have to put it in a repeating command block or in a ticking function (a function running every tick) the following command.
execute as @a at @s store result score @s xpos run data get entity @s Pos[0]
That will at every tick store the x value of every player in the world to their scoreboard value. This is multiplayer friendly. Next, we test if they have a specific value or a range in the scoreboard with the following command.
execute as @a[scores={xpos=<range/value>}] at @s run tp <cordinates>
Keep in mind, for this to work, both commands I gave you must be in a repeating command block or in a ticking function. In your case replace <range/value>
with 5375..
and <cordinates>
to -5375 ~ ~
. If you have any questions please ask I'll be happy to help.