I am making a HealthBar, with a damage visual. But I want it to where when you take quick damage in a certain amount of time.
It wont look like this:
Instead, it will clump together in 1 big bar. The code looks like this
local function UpdateHp(gui, humanoid)
local HealthDisplay = gui.HealthFrame
local Fill = HealthDisplay.HealthVisual :: Frame
local life = humanoid.Health / humanoid.MaxHealth
local color = nil
life = math.clamp(life, 0, 1)
local FillTween = TweenService:Create(
Fill,
TWEEN_INFO,
{
Size = UDim2.fromScale(life, 1),
BackgroundColor3 = Color3.fromHSV(life/3, 1, 1)
}
)
FillTween:Play()
if LastHealth > life then -- Checks if they actually look damage
local tempframe = Fill:Clone()
tempframe.ZIndex = -1
tempframe.BackgroundColor3 = WHITE
tempframe.BorderSizePixel = 0
tempframe.Name = "DamageVisualTemporary"
tempframe.Parent = HealthDisplay
task.delay(0.25, function()
local Tween = TweenService:Create(
tempframe,
TweenInfo.new(0.35, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 1),
{
Size = UDim2.fromScale(life, 1),
}
)
Tween:Play()
Tween.Completed:Once(function()
tempframe.BackgroundTransparency = 1
Debris:AddItem(tempframe, 0.25)
end)
end)
end
HealthDisplay.HealthNumber.Text = string.format(
"%i / %i",
math.ceil(humanoid.Health),
math.ceil(humanoid.MaxHealth)
)
LastHealth = life
end
function SetHealthBar(humanoid, root)
local player = Players:GetPlayerFromCharacter(humanoid.Parent)
local Base = BaseGui:Clone()
local HealthDisplay = Base.HealthFrame
local TextName = Base.NameFrame.PlayerName
local DisplayName = player.DisplayName
Base.Adornee = root
Base.Parent = root
TextName.Name = DisplayName
TextName.TextColor3 = player.TeamColor.Color
TextName.Text = DisplayName
local function updatethisone()
UpdateHp(Base, humanoid)
end
local tc1 = humanoid:GetPropertyChangedSignal("Health"):Connect(updatethisone)
local tc2 = humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(updatethisone)
local tc3 = humanoid:GetPropertyChangedSignal("DisplayName"):Connect(function()
TextName.Text = DisplayName
end)
local tc4 = player:GetPropertyChangedSignal("TeamColor"):Connect(function(TeamColor)
TextName.TextColor3 = TeamColor.Color
end)
humanoid.Died:Connect(function()
if tc1 then tc1:Disconnect() end
if tc2 then tc2:Disconnect() end
if tc3 then tc3:Disconnect() end
if tc4 then tc4:Disconnect() end
updatethisone()
end)
humanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
updatethisone()
end
If I could get even a starter on how I’d begin to do this, It would be appreciative!