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

Script gui problem?

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

4 comments

0

What type of objects are Health and MaxHealth?

0

Don't you need Humanoid.Health and Humanoid.MaxHealth?

0

Enemy is the rename of Humanoid

0

Updated my answer

1 answer

✓ 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!

2 comments

0

Health and maxhealth are not values. When i take away the .Value from health and maxhealth it still doesn't work :/

0

Properties of humanoid

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