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

Why My Health Bar is Breaking When Taking Damage Twice?

Asked by 5 years ago
Edited 5 years ago

Hello everyone! So I've been spending the last few days figuring out how to fix my health bar GUI. So it is meant to smoothly decrease when the player takes damage. All that is working however, when a player takes damage twice or more without the script finishing its function, it all stops working. Please ask me any questions if you have any, and also the size of my health bar is {0,200}, {0, 100}.

--// Variables //--

local HUD = script.Parent
local HealthBar = HUD.Health
local Mob = Hud.Parent.Parent --Character
local Humanoid = Mob.Humanoid 
local CurrentHealth = 100*2 -- Multiplying it by 2 to make it proportional to the length of the healthbar.


--// Health //--

function HChanged()
local Health = Humanoid.Health
local Size = Health*2
for NewSize = CurrentHealth,Size,(-Health+10)/10 do
HealthHud.Size = UDim2.new(0, NewSize,0,7) --// 7 is the width.
wait()
end
CurrentHealth = Health*2
end    
HChanged()
Humanoid.Changed:Connect(HChanged)
0
CODE BLOCK PLEASE! Gameplayer365247v2 1055 — 5y
0
Are you trying to change the health bar smoothly with that for loop? MegaManSam1 207 — 5y

Answer this question