I have a NumberValue object within a GUI script and I’m able to get it showing correctly, It’s just not properly updating.
local SanityNumber = game.Players.LocalPlayer.PlayerGui.GeneralInfo.A.TextLabel.Sanity
local textInfo = game.Players.LocalPlayer.PlayerGui.GeneralInfo.A.TextLabel
local sanityValue = game.Players.LocalPlayer.PlayerGui.GeneralInfo.A.TextLabel.Sanity.Value
while wait(0.05) do
print("Santiy Drain")
textInfo.Text = "Sanity:"..sanityValue
end
It updates to “Sanity: 100” But it doesn’t actually update the sanity number itself (100). The number in the NumberValue will continue to descend but the text gui wont update, despite it being told to update in a while wait loop.
If I need to add photos or something lmk. Any help is appreciated
And no, I don’t get any errors when the script runs.
This is not entirely accurate. You don’t need a remote event in this case because the IntValue exists within the PlayerGui and is therefore a local instance which does not replicate to the server.
Couple of things to point out here. This line is where the problem resides:
local sanityValue = game.Players.LocalPlayer.PlayerGui.GeneralInfo.A.TextLabel.Sanity.Value
You are retrieving the initial value from the Sanity instance. The variable sanityValue does not update dynamically as you’re expecting it to.
This is a better approach and avoids using a while loop.
local SanityNumber = game.Players.LocalPlayer.PlayerGui.GeneralInfo.A.TextLabel.Sanity
local textInfo = game.Players.LocalPlayer.PlayerGui.GeneralInfo.A.TextLabel
local sanity = game.Players.LocalPlayer.PlayerGui.GeneralInfo.A.TextLabel.Sanity
textInfo.Text = "Sanity:"..sanity.Value
sanity.Changed:Connect(function(newVal)
textInfo.Text = "Sanity:"..newVal
end)
Yes, This is it! Oh thank you, Thank you so much! I noticed that once the value reached between 30 - 40 I had a lot of lag (With the code I provided, your code has no lag). I figured it might have been because as time went by the server was “Updating” the text so much that it just ate up memory.