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
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