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

Script gui problem?

Asked by 8 years ago

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
0
What type of objects are Health and MaxHealth? Programmix 285 — 8y
0
Don't you need Humanoid.Health and Humanoid.MaxHealth? dragonkeeper467 453 — 8y
0
Enemy is the rename of Humanoid Anthony9960 210 — 8y
0
Updated my answer Programmix 285 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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!

0
Health and maxhealth are not values. When i take away the .Value from health and maxhealth it still doesn't work :/ Anthony9960 210 — 8y
0
Properties of humanoid Anthony9960 210 — 8y
Ad

Answer this question