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

Why isn't my GUI updating when I change positions? [SOLVED BY MYSELF]

Asked by 4 years ago
Edited 4 years ago

I am having some trouble with my code because I'm fairly new at scripting. I'm trying to create some code that will update a GUI whenever the player's HumanoidRootPart changes positions(Y-Axis), and I'm not sure what code to use to update it. I'm thinking of using a while loop but I'm not sure where to add it. The code is in a LocalScript and there are no errors in the output.

Any recommendations/help is appreciated.

Here is the code:

1game.Workspace:WaitForChild("Humanoid",0.05)
2 
3    local character = game.Players.LocalPlayer.Character
4    local textLabel = script.Parent
5    local rootpartPositionY = character.HumanoidRootPart.Position.Y
6    local rootpartPositionYnum = math.floor(rootpartPositionY*1)/1
7 
8                        -- not sure what to add here
9textLabel.Text = (rootpartPositionYnum .." s")

EDIT: I have fixed this code by adding a "while true do" at the start of my code. Like this:

01while true do -- this is new
02game.Workspace:WaitForChild("Humanoid",0.05)
03wait()  --this is new
04    local character = game.Players.LocalPlayer.Character
05    local textLabel = script.Parent
06    local rootpartPositionY = character.HumanoidRootPart.Position.Y
07    local rootpartPositionYnum = math.floor(rootpartPositionY*1)/1
08 
09textLabel.Text = (rootpartPositionYnum .." s")
10end -- new
0
like you said, never forget loops when something needs to be checked more than once WideSteal321 773 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I have fixed this code by adding a "while true do" at the start of my code. Like this:

01while true do -- this is new
02game.Workspace:WaitForChild("Humanoid",0.05)
03wait()  --this is new
04    local character = game.Players.LocalPlayer.Character
05    local textLabel = script.Parent
06    local rootpartPositionY = character.HumanoidRootPart.Position.Y
07    local rootpartPositionYnum = math.floor(rootpartPositionY*1)/1
08 
09textLabel.Text = (rootpartPositionYnum .." s")
10end -- new
Ad

Answer this question