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

How to make a Surface Gui (Box) show a humanoids Health??

im trying to make a wall that has 2500 health and a surface gui on it saying the current health of the wall (Humanoid) except when i damage the wall (Humanoid) the surface gui text should change but it doesnt.

repeat
script.Parent.CurHealth.Text = script.Parent.Parent.Parent.Humanoid.Health
until script.Parent.Parent.Parent.Humanoid.Health

PLEASE HELP!

1 comment

0

THANKS!!!

1 answer

✓ Accepted answer

Your script is basically saying to repeat setting the text of CurHealth to the Humanoid Health until the Humanoid Health is what it currently is, which won't really do anything.

What you're looking for is an updater that makes CurHealth set to the Humanoid's health every time the Humanoid's health changes.

function onHealthChanged()
	script.Parent.CurHealth.Text = script.Parent.Parent.Parent.Humanoid.Health
end

script.Parent.Parent.Parent.Humanoid.HealthChanged:connect(onHealthChanged)

The HealthChanged event accepts a parameter, and the value of it is the value of the health changed to (i.e. final health).

So you could also do this.

function onHealthChanged(health)
	script.Parent.CurHealth.Text = health
end

script.Parent.Parent.Parent.Humanoid.HealthChanged:connect(onHealthChanged)

I hope this helps. If it doesn't, I'll give it another look.

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