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

Humanoid Health wont update???

Asked by
Galicate 106
6 years ago

I have a simple script that i have no clue why it wont work. The humanoid takes damage but doesnt change to value of health or change the humanoids health, even though the health bar above the character lowers.

health = game.Workspace.Objective.Humanoid.Health

while true do
    wait(0.01)
    script.Parent.Text = ("Supply Health || " .. health)
    end
0
That is because you should have said on line 5 health.Value greatneil80 2647 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

Im assuming that this code is the entire script in which case, you are only setting the variable health once. Instead you should also set it in the loop, so that every time the loop repeats it gets the current health instead of the health that was declared at the beginning of the script. Also instead of wait(0.01) try wait() So try this:

while true do
    wait()
    health = game.Workspace.Objective.Humanoid.Health
        script.Parent.Text = ("Supply Health || " .. health)
end

Hope this helps.

Ad
Log in to vote
0
Answered by 6 years ago

ahhh here

health = workspace.Objective.Humanoid.Health

health.Changed:connect(function()
    script.Parent.Text = "Supply Health ||  "..health
end)

Using the changed function will make it so every time the objective health changes the text will update. This is more efficient because now this will lower the chance of unexpected breaks because

while true do

loops aren't good for anything. So if anything do

while wait() do

so breaks won't happen as often.

Answer this question