Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Player Position displayed in GUI doesn't update?

Asked by 5 years ago

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.

01local textLabel = script.Parent
02local text = textLabel.Text
03 
04local Players = game:GetService("Players")
05local player = Players.LocalPlayer
06local character = player.Character or player.CharacterAdded:wait() -- in case the character model has already been created
07local playerCoords
08 
09if character ~= nil then
10    playerCoords  = character:WaitForChild("HumanoidRootPart").Position
11end
12 
13 
14while true do
15    local intCoords = Vector3.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()
19end

Why does it only update once at the beginning? Even though it is still running and keeps printing the same intCoords value?

3 answers

Log in to vote
0
Answered by
VVoretex 146
5 years ago
Edited 5 years ago

use this:

1while true do
2wait() -- put whatever wait you want
3script.Parent.Text = game.Players.Character:WaitForChild("Torso").Position -- change this to LowerTorso if r15
4--rest of code
5end

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

0
wait it worked? VVoretex 146 — 5y
0
I will explain VVoretex 146 — 5y
0
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 User#34187 8 — 5y
0
I'm not sure i think you were getting HumanoidRootPart not Torso VVoretex 146 — 5y
View all comments (7 more)
0
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? User#34187 8 — 5y
0
you used tostring Im pretty sure you do: script.Parent.Text = game.Players.Localplayer.Character:WaitForChild("Torso").Position VVoretex 146 — 5y
0
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 User#34187 8 — 5y
0
is it localscript? VVoretex 146 — 5y
0
also thanks for the reputation! VVoretex 146 — 5y
0
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 User#34187 8 — 5y
0
yeah it was a pretty good question VVoretex 146 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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:

01local textLabel = script.Parent
02local text = textLabel.Text
03 
04local Players = game:GetService("Players")
05local player = Players.LocalPlayer
06local character = player.Character or player.CharacterAdded:wait() -- in case the character model has already been created
07local playerCoords
08 
09if character ~= nil then
10    playerCoords  = character:WaitForChild("HumanoidRootPart").Position
11    print("Got root")
12end
13 
14 
15while true do
View all 23 lines...
Log in to vote
-2
Answered by 5 years ago

print("sub to my youtube")

0
Ah, yes, so this is why the DevForum is so heavily restricted User#34187 8 — 5y
0
:/ Nguyenlegiahung 1091 — 5y
0
omg stopp LUCATIVIOMAD2 54 — 5y
0
dont be a jerk jayden VVoretex 146 — 5y

Answer this question