Coordinate script

I want to make a coordiante script, I know how to get the coordiantes but i dont know where to put this script, nor how to print the values on an UI
PS: Sorry if there are any grammar mistakes in this script, i wrote it in here without autocorrect,

Local player = workspace.Players.LocalPlayer
Local x = player.Character.HumanoidRootPart.Position.x
Local y = player.Character.HumanoidRootPart.Position.y
Local z = player.Character.HumanoidRootPart.Position.z

Thanks in advance.

2 Likes

Players is not in workspace, It’s in the DataModel (game, so game.Players.LocalPlayer). To print these values out, you would just do: print("X value: "..tostring(x).."\nY value: "..tostring(y).."\nZ value: "..tostring(z))
Keep in mind to constantly get the coordinates, you would need to put the above code inside of a loop.

1 Like

So like this?

Local player = game.Players.LocalPlayer
Local coordinates = {
Local x = 
player.Character.HumanoidRootPart.Position.x
Local y = player.Character.HumanoidRootPart.Position.y
Local z = player.Character.HumanoidRootPart.Position.z
}
For i, v in pairs(coordinates) do
Blablabla
end)

No, don’t put it in a table. Also, your loop is wrong, for should not be capitalized and you need to specify something inside of pairs() – Check out this link to learn more about loops. I was also thinking more of a while condition do loop, but for wouldn’t work without a table anyways.

1 Like

Yeah i just forgot, I’m writing this on mobile and in here so uppercases might be wrong.

1 Like

Please do not capitilize local. Roblox Lua will not register it.

1 Like

My phone makes uppercases automatically sorry

1 Like

So if i dont do a loop, the coordinates will print only once, and wont update?

No, it will not update, with that being said you should put this localscript inside of StarterCharacterScripts since it may error if the player’s character hasn’t loaded in to the game before the player (which is impossible).

1 Like

Im still a bit confused on the loop, why doesn’t the in pairs work?

pairs() requires a table, and it’s just easier to put all the values in X, Y, and Z variables, but if you really want to use a table, don’t use local inside those tables. Instance:

local coords = {
x = 1,
y = 2,
y = 3 -- change these values to fit your code
}
1 Like

I dont really want to make a table per say, thats the only loops i came up with, since you said that a loop is needed.

Anyways, I should experiment first on studio.

And my biggest problem is printing the x,y and z values on an ui

Just change a TextLabel’s .Text property to a new string or add on to it by using TextLabel.Text = TextLabel.Text + " hello, world!"
so if the textlabel’s .Text property was “Hm”, the new textlabel’s .Text property would be “Hm hello, world!”

1 Like

But then i’d have to make a loop, so every time the coordinates change, the text updates

Then just omit the “TextLabel.Text +” and just do "TextLabel.Text = ‘str’ "

1 Like

I dont understand, whats omit?

it’s basically to just take out or remove something.

1 Like

So no need to do a loop, it automatically updates?

1 Like