✓ Accepted answer
Here's the issue:
Assuming MaxHealth and Health are Value objects, you'll need to do this instead of your while loop.
local Enemy = ZombieKing.Enemy
Enemy.Changed:connect(function()
Bar.Size = UDim2.new(Enemy.Health / Enemy.MaxHealth, 0, 1, 0)
end)
That should fix your problem.
Allow me to explain what changed.
Instead of using a while loop to update your bar rapidly, using the .Changed event of Humanoid (and many more) objects is a much better alternative, as it will make updating faster, and won't waste time trying to update it hundreds of times per second.
Also, you can't just divide the Health property of a Humanoid by the MaxHealth property as variables. You have to index them from the Humanoid itself.
I hope this helped. Good luck!
4 comments
What type of objects are Health and MaxHealth?
Don't you need Humanoid.Health and Humanoid.MaxHealth?
Enemy is the rename of Humanoid
Updated my answer