Minecraft – How to set a player’s scoreboard score to a player’s coordinates [1.15.2]

minecraft-commandsminecraft-java-edition

I am creating a map in Minecraft Java Edition 1.15.2.

I would like to be able to get the X coordinate of a player and store it in a scoreboard value.

How can I do this?

Best Answer

This can be accomplished fairly easily using the /execute store and /data get commands:

/execute store result score <player or fake player name> <objective name> run data get entity <player> Pos[0]

(the Pos array is in the order [X, Y, Z], so Pos[0] is the X coordinate)