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

Why when i reset my Health Gui Size is at 0?

So i have a full Gui bar of health, once i reset and respawn, my bar is at 100% length but after 3 seconds it changed the size to zero. Could it be that since I'm using a changed function, the size was 0 after i died, so when i respawned it changed back to zero. Anyway, here is the script, please help :(

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local hum = char:WaitForChild("Humanoid")

local inner = script.Parent.InnerBar

wait(3)

hum.Changed:connect(function(update)
	inner.Size = UDim2.new(hum.Health/460, 0, 0, 8) --UDim2.new(hum.Health/362, 0, 0, 8)
end)

9 comments

0

Remove the 'wait(3)'.That is the 3 second delay.

0

That just made the bar size change to 0 even faster @DigitalVeer :(

0

You are doing it incorrectly; For how I get the full health is, I divide the Humanoid's Health by it's MaxHealth, then Multiply the number afterwards by the GUI size number. [(Health/MaxHealth)*SizeOfGui]

0

So i would do hum.Health/hum.MaxHealth*280? that even makes the bar longer which i don't want :(

0

And that didn't really solve my problem, the Size still changes to ZERO (0) after i respawn :(

0

What is the Size of your GUI? Is it like {1,0,1,0}?

0

The size of the GUI is [0, 280, 0, 8]

0

Then you would Divide and Multiply the Health and MaxHealth multiplying that Number.

0

what number? there are two. 280 and 8 :/

3 answers

From past experience, in my opinion, or, in my own way, you HAVE to Divide a Player's Health by it's MaxHealth, and, from the comments you replied with, the GUI's size is 0, 280, 0, 8, we would [probably] divide the Number 280. Now, with this in mind, let us fix your code;

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local hum = char:WaitForChild("Humanoid")

local inner = script.Parent.InnerBar

wait(3) --Why is this needed, exactly?

hum.Changed:connect(function(update)
    inner.Size = UDim2.new(0, (hum.Health/hum.MaxHealth)*280, 0, 8) --This will divide the Player's Health property by it's MaxHealth property, then will multiply that number by '280', changing the Size depending on the Health property number divided by it's MaxHealth property.
end)

Hope this helped!

2 comments

0

Yeah but that didn't solve my problem. After i reset and respawn, my health bar GU size changes back to 0 :(

0

I'm confused, what do you mean by it changes back to '0'?

You can remove the argument "update" from the function; you don't use it anyway.

inner.Size = UDim2.new(hum.Health / hum.MaxHealth, 0, 0, 8)

2 comments

0

Well that didn't help :(

0

Could you please explain why it didn't help?

Might want to play my Assassin's Creed Alpha game on my profile. Reset, then see what i mean :/

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