I have this script inside StarterGui, attached to a TextLabel. The script displays my character's position once, at the beggining, but then stops updating, even though other functions inside it's while loop keep running.
local textLabel = script.Parent
local text = textLabel.Text
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait() -- in case the character model has already been created
local playerCoords
if character ~= nil then
playerCoords = character:WaitForChild("HumanoidRootPart").Position
end
while true do
local intCoords = Vector3.new(math.floor(playerCoords.X + 0.5), math.floor(playerCoords.Y + 0.5), math.floor(playerCoords.Z + 0.5))
textLabel.Text = tostring(intCoords)
print(intCoords)
wait()
end
Why does it only update once at the beginning? Even though it is still running and keeps printing the same intCoords value?

11 comments
wait it worked?
I will explain
Sorry, I made a typo and had to delete the comment. Yes, I had to change "Players.Character" to "Players.LocalPlayer.Character" but yes, it worked. I'm guessing I wasn't creating a reference to the variable but only copying the value at the time I read it? Weird
I'm not sure i think you were getting HumanoidRootPart not Torso
Yeah, I'm using R16 so I also changed that bit. The whole line of code I used was: "script.Parent.Text = tostring(game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position)". Thanks for the edit. But you know why it doesn't update inside the while loop?
you used tostring Im pretty sure you do: script.Parent.Text = game.Players.Localplayer.Character:WaitForChild("Torso").Position
If I don't use tostring() I get the following error: " ... bad argument #3 (string expected, got Vector3)". So you do need to use it
is it localscript?
also thanks for the reputation!
Yeah, it's a LocalScript. I've posted a full answer now. No worries. Please upvote my question and/or answer if you find them useful
yeah it was a pretty good question