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

How do i make this mob health updater work?

im trying to make a health bar for this mob and it will update upon when the mob is damaged but its not working here is the script

while true do
	script.Parent.HP.Text = script.Parent.Parent.Parent.Humanoid.Health / script.Parent.Parent.Parent.Humanoid.MaxHealth
    wait()
end

1 answer

✓ Accepted answer

Hello MPforfun,

The reason that your code is not working is because you are dividing the amount of the mob's current health by its max health instead of displaying it. Not only that but you should try to avoid .Parent a lot of times. Makes the code look really messy. And we do not need a while loop for this scenario. Here is the fixed script:

local mob = script.Parent.Parent.Parent
local mobHumanoid = mob:WaitForChild("Humanoid")
local UIobject = script.Parent:WaitForChild("HP")

mobHumanoid:GetPropertyChangedSignal("Health"):Connect(function()	
	UIobject.Text = mobHumanoid.Health.."/"..mobHumanoid.MaxHealth
end)	                   	

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