I am making a custom health bar gui but there is a moderate issue with it. Everything about it works as accordingly except for whenever the player takes damage, the health bar suddenly spikes in health and then goes back to normal after a split second. It is pretty annoying and can definitely interrupt the experience.
what i mean:
oh and the code too:
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local title = script.Parent.Parent.Title
local health = 100
humanoid.HealthChanged:Connect(function(Damage)
if Damage < health then
script.Parent.Size = UDim2.new(Damage / humanoid.MaxHealth, 0, 1, 0)
local output = math.round(Damage)
title.Text = output.."/100"
health = Damage
if output >= 90 then
script.Parent.BackgroundColor3 = Color3.fromRGB(103, 197, 102)
elseif output >= 80 and output < 90 then
script.Parent.BackgroundColor3 = Color3.fromRGB(124, 197, 104)
elseif output >= 70 and output < 80 then
script.Parent.BackgroundColor3 = Color3.fromRGB(149, 197, 110)
elseif output >= 60 and output < 70 then
script.Parent.BackgroundColor3 = Color3.fromRGB(174, 197, 120)
elseif output >= 50 and output < 60 then
script.Parent.BackgroundColor3 = Color3.fromRGB(188, 197, 111)
elseif output >= 40 and output < 50 then
script.Parent.BackgroundColor3 = Color3.fromRGB(208, 200, 106)
elseif output >= 30 and output < 40 then
script.Parent.BackgroundColor3 = Color3.fromRGB(197, 159, 93)
elseif output >= 20 and output < 30 then
script.Parent.BackgroundColor3 = Color3.fromRGB(197, 136, 93)
elseif output >= 10 and output < 20 then
script.Parent.BackgroundColor3 = Color3.fromRGB(197, 96, 78)
elseif output >= 0 and output < 10 then
script.Parent.BackgroundColor3 = Color3.fromRGB(197, 54, 54)
end
script.Parent.Parent.Parent.Frame.Visible = true
script.Parent.Parent.Parent.Frame.ImageTransparency = .5
repeat
wait(.000001)
script.Parent.Parent.Parent.Frame.ImageTransparency += .02
until script.Parent.Parent.Parent.Frame.ImageTransparency == 1
end
wait(.000001)
health = Damage
script.Parent.Size = UDim2.new(Damage / humanoid.MaxHealth, 0, 1, 0)
local output = math.round(Damage)
title.Text = output.."/100"
if output >= 90 then
script.Parent.BackgroundColor3 = Color3.fromRGB(103, 197, 102)
elseif output >= 80 and output < 90 then
script.Parent.BackgroundColor3 = Color3.fromRGB(124, 197, 104)
elseif output >= 70 and output < 80 then
script.Parent.BackgroundColor3 = Color3.fromRGB(149, 197, 110)
elseif output >= 60 and output < 70 then
script.Parent.BackgroundColor3 = Color3.fromRGB(174, 197, 120)
elseif output >= 50 and output < 60 then
script.Parent.BackgroundColor3 = Color3.fromRGB(188, 197, 111)
elseif output >= 40 and output < 50 then
script.Parent.BackgroundColor3 = Color3.fromRGB(208, 200, 106)
elseif output >= 30 and output < 40 then
script.Parent.BackgroundColor3 = Color3.fromRGB(197, 159, 93)
elseif output >= 20 and output < 30 then
script.Parent.BackgroundColor3 = Color3.fromRGB(197, 136, 93)
elseif output >= 10 and output < 20 then
script.Parent.BackgroundColor3 = Color3.fromRGB(197, 96, 78)
elseif output >= 0 and output < 10 then
script.Parent.BackgroundColor3 = Color3.fromRGB(197, 54, 54)
end
end)