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.
01 | local textLabel = script.Parent |
02 | local text = textLabel.Text |
03 |
04 | local Players = game:GetService( "Players" ) |
05 | local player = Players.LocalPlayer |
06 | local character = player.Character or player.CharacterAdded:wait() -- in case the character model has already been created |
07 | local playerCoords |
08 |
09 | if character ~ = nil then |
10 | playerCoords = character:WaitForChild( "HumanoidRootPart" ).Position |
11 | end |
12 |
13 |
14 | while true do |
15 | local intCoords = Vector 3. new(math.floor(playerCoords.X + 0.5 ), math.floor(playerCoords.Y + 0.5 ), math.floor(playerCoords.Z + 0.5 )) |
16 | textLabel.Text = tostring (intCoords) |
17 | print (intCoords) |
18 | wait() |
19 | 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:
1 | while true do |
2 | wait() -- put whatever wait you want |
3 | script.Parent.Text = game.Players.Character:WaitForChild( "Torso" ).Position -- change this to LowerTorso if r15 |
4 | --rest of code |
5 | 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:
01 | local textLabel = script.Parent |
02 | local text = textLabel.Text |
03 |
04 | local Players = game:GetService( "Players" ) |
05 | local player = Players.LocalPlayer |
06 | local character = player.Character or player.CharacterAdded:wait() -- in case the character model has already been created |
07 | local playerCoords |
08 |
09 | if character ~ = nil then |
10 | playerCoords = character:WaitForChild( "HumanoidRootPart" ).Position |
11 | print ( "Got root" ) |
12 | end |
13 |
14 |
15 | while true do |
print("sub to my youtube")