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?
use this:
while true do wait() -- put whatever wait you want script.Parent.Text = game.Players.Character:WaitForChild("Torso").Position -- change this to LowerTorso if r15 --rest of code end
hope it helps c:
A simple Explanation:
The player's Torso or LowerTorso is the player model's PrimaryPart, since all models use a PrimaryPart to move, or detect a model's position, Also, you do not continuously change the text with while true do, so it will only show the coordinates once.
for any more info, use this DevForum:
https://developer.roblox.com/en-us/api-reference/property/Model/PrimaryPart
Thanks @VortexGamingPlayerYT for the directions.
Here's the full script for anyone wanting to do the same thing. Put this code in a LocalScript inside a TextLabel in StarterGui:
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 print("Got root") end while true do -- access the position variable every frame local intCoords = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position -- round down each axis with math.floor() to get only integers intCoords = Vector3.new(math.floor(intCoords.X), math.floor(intCoords.Y), math.floor(intCoords.Z)) -- assign it to the text label with tostring() so you don't pass a Vector3 textLabel.Text = tostring(intCoords) wait() end
print("sub to my youtube")