This is a local script inside a frame. I'm trying to make a boss health bar, but it does not work.
local ZombieKing = game.Workspace:WaitForChild("ZombieKing") local MaxHealth = ZombieKing.Enemy.MaxHealth local Health = ZombieKing.Enemy.Health local Bar = script.Parent while wait() do Bar.Size = UDim2.new(Health/MaxHealth,0,1,0) end
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!