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

How do i make this mob health updater work?

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
1
Answered by
valchip 789 Moderation Voter
5 years ago

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)                        
Ad

Answer this question