Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 10 years ago

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!

0
THANKS!!! SirKitten2000 0 — 10y

1 answer

Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
10 years ago

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.

Ad

Answer this question