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:

game.Workspace:WaitForChild("Humanoid",0.05)

    local character = game.Players.LocalPlayer.Character
    local textLabel = script.Parent
    local rootpartPositionY = character.HumanoidRootPart.Position.Y
    local rootpartPositionYnum = math.floor(rootpartPositionY*1)/1

                        -- not sure what to add here
textLabel.Text = (rootpartPositionYnum .." s")

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

while true do -- this is new
game.Workspace:WaitForChild("Humanoid",0.05)
wait()  --this is new
    local character = game.Players.LocalPlayer.Character
    local textLabel = script.Parent
    local rootpartPositionY = character.HumanoidRootPart.Position.Y
    local rootpartPositionYnum = math.floor(rootpartPositionY*1)/1

textLabel.Text = (rootpartPositionYnum .." s")
end -- 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:

while true do -- this is new
game.Workspace:WaitForChild("Humanoid",0.05)
wait()  --this is new
    local character = game.Players.LocalPlayer.Character
    local textLabel = script.Parent
    local rootpartPositionY = character.HumanoidRootPart.Position.Y
    local rootpartPositionYnum = math.floor(rootpartPositionY*1)/1

textLabel.Text = (rootpartPositionYnum .." s")
end -- new

Ad

Answer this question