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

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

Asked by 9 years ago

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)
0
Remove the 'wait(3)'.That is the 3 second delay. DigitalVeer 1473 — 9y
0
That just made the bar size change to 0 even faster @DigitalVeer :( NonSpace 0 — 9y
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] TheeDeathCaster 2368 — 9y
0
So i would do hum.Health/hum.MaxHealth*280? that even makes the bar longer which i don't want :( NonSpace 0 — 9y
View all comments (5 more)
0
And that didn't really solve my problem, the Size still changes to ZERO (0) after i respawn :( NonSpace 0 — 9y
0
What is the Size of your GUI? Is it like {1,0,1,0}? TheeDeathCaster 2368 — 9y
0
The size of the GUI is [0, 280, 0, 8] NonSpace 0 — 9y
0
Then you would Divide and Multiply the Health and MaxHealth multiplying that Number. TheeDeathCaster 2368 — 9y
0
what number? there are two. 280 and 8 :/ NonSpace 0 — 9y

3 answers

Log in to vote
1
Answered by 9 years ago

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!

0
Yeah but that didn't solve my problem. After i reset and respawn, my health bar GU size changes back to 0 :( NonSpace 0 — 9y
0
I'm confused, what do you mean by it changes back to '0'? TheeDeathCaster 2368 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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)
0
Well that didn't help :( NonSpace 0 — 9y
0
Could you please explain *why* it didn't help? Programmix 285 — 9y
Log in to vote
0
Answered by 9 years ago

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

Answer this question