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

Humanoid Health wont update???

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

1 comment

0

That is because you should have said on line 5 health.Value

2 answers

✓ Accepted answer

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.

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.

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