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)
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!
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)
Might want to play my Assassin's Creed Alpha game on my profile. Reset, then see what i mean :/