I am trying to recreate that effect that many games have that when you take damage the green healthbar will go down and there will be a red healthbar that goes down afterwards. I am tweening the red healthbar but it is making it move instantly instead of actually tweening. Here is the healthbar :
Here is the script that gets fired every time the player takes damage. The event sends over the players current HP , max Hp and if it is an increase or decrease in HP :
local HealthGui = PlayerGUI:WaitForChild("healthGUI")
local GreenBar = HealthGui.HPframe.HealthDisplay
local RedBar = HealthGui.HPframe.SecondaryHealthDisplay
local HealthEvent = game.ReplicatedStorage["RemoteEvents(s->c)"].HealthEvent
local TweenService = game:GetService("TweenService")
HealthEvent.OnClientEvent:Connect(function(HP,Max,Increase)
local BarSize = HP/Max
if Increase then
GreenBar.Size = UDim2.new(BarSize,0,1,0)
else
RedBar.Size= GreenBar.Size
GreenBar.Size = UDim2.new(BarSize,0,1,0)
local info = TweenInfo.new(
4,
Enum.EasingStyle.Exponential,
Enum.EasingDirection.Out,
0,
false,
1
)
local Goals = {
Size = UDim2.new(BarSize,0,1,0)
}
local track = TweenService:Create(RedBar,info,Goals)
track:Play()
end
end)
Also I have tried using tweenservice and UI:TweenSize() but both have the same problem.