Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Text occasionally isn't changing in correspondance to an IntValue?

I have a script that changes the text on a health bar to correspond with an HP value, most of the time it works fine but occasionally it bugs out and either doesn't change the text to the new value or changes the text to a value I changed it to previously. If I click onto the text label it updates or something and changes to the correct value. Is this just a visual bug in Studio or is there something wrong with my script?

hpv = script.Parent.Parent.Parent.Parent.Parent.Parent:WaitForChild('ZombieStats'):WaitForChild('HealthPoints')

hpv.Changed:Connect(function()
	if hpv.Value > 0 then
		script.Parent.Text = (hpv.Value..' HP')
	else
		hpv.Value = 0
		script.Parent.Text = ('0 HP')
	end
end)

1 comment

0

The script below won't cause too much lag as even if it updates every second or so, the values won't change much unless the player is getting anything. Therefore, the code only acts when there is a change in leaderstats or hpv in this case

1 answer

Here is a better script that updates every time!

hpv = script.Parent.Parent.Parent.Parent.Parent.Parent:WaitForChild('ZombieStats'):WaitForChild('HealthPoints')

while wait() do -- Every few seconds, do
    if hpv.Value > 0 then
        script.Parent.Text = (hpv.Value..' HP')
    else
        hpv.Value = 0
        script.Parent.Text = ('0 HP')
    end
end

2 comments

1

My reason for having it update only when the value changed was to reduce updates to the game since I'm going to have a large amount of these working at once, would this script cause more lag or no?

0

Not sure how this will resolve his issue.

This discussion is preserved as it was. New answers, comments, and votes are closed.