1. What do you want to achieve?
I want the health bar gui lower your life as same as fast as the roblox common health bar
2. What is the issue?
3. What solutions have you tried so far?
I have search around the forum for some simillar cases but I haven´t finded anything so similar
--//Variables//--
local Character = script.Parent
local HealthBarGui = Character.Head.HealthBarGui
local Humanoid = Character.Humanoid
--//Functions//--
Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
local HealthChange = Humanoid.Health/Humanoid.MaxHealth
HealthBarGui.GreyHealth.GreenHealth:TweenSize(UDim2.new(HealthChange,0,1,0),"In","Linear",1)
end)
This is my first post, thank you in advance for answering.
If my question already has an obvious answer, then I apologize for my ignorance.
you can remove ‘1’ after “Linear” or just decrease the number to make it faster, that number represents how fast the tweening must be, if you don’t put any number, the system will decide itself. And if you want a smoother transition I suggest using “Quad” or “Sine” rather than “Linear”
It’s most likely an override issue. This can be solved by setting the override of TweenSize to true.
TweenSize(UDim2.new(HealthChange,0,1,0),“In”,“Linear”,1, true))
I always hated TweenSize. Using TweenService is way more professional and flexible.
To integrate it into your code:
--//Variables//--
local Character = script.Parent
local HealthBarGui = Character.Head.HealthBarGui
local Humanoid = Character.Humanoid
--//Functions//--
Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
local HealthChange = Humanoid.Health/Humanoid.MaxHealth
game:GetService('TweenService'):Create(HealthBarGui.GreyHealth.GreenHealth, TweenInfo.new(1), {Size = Udim2.fromScale(HealthChange,1)}):Play() -- Creates a tween with parameters: object, info, goal
end)
If that doesn’t help, I suggest you take a look at my HealthBar’s source.
If you mean it’s too slow then change the Time argument, which indicates how fast it finishes:
HealthBarGui.GreyHealth.GreenHealth:TweenSize(UDim2.new(HealthChange,0,1,0),"In","Linear",1)
This one ^
So changing that value to let’s say, 0.1 would make it so that every time the player loses HP it takes 0.1 seconds to go down all the way.
On a further note, TweenSize is deprecated and TweenService is a much better way to go around this(although TweenSize is okay to use, it’s not supported anymore).