Problems with the health bar gui

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.

1 Like

Hmm, that’s very strange. Could you add these prints so we can see what the problem is:

--//Variables//--
local Character = script.Parent
local HealthBarGui = Character.Head.HealthBarGui
local Humanoid = Character.Humanoid

--//Functions//--
Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
        print("Changing Health")
	    local HealthChange = Humanoid.Health/Humanoid.MaxHealth
        print(Humanoid.Health)
        print(Humanoid.MaxHealth)
        print(HealthChange)
        HealthBarGui.GreyHealth.GreenHealth:TweenSize(UDim2.new(HealthChange,0,1,0),"In","Linear",1)
end)

Let me know if any of these print something that doesn’t make sense.

You could just remove TweenSize and just set its position.

1 Like

He probably wants to make it drop down smoothly.

So maybe change the speed of the tween.

1 Like

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”

Same response, it does the same thing as my script

It’s the same exact code except there are some prints. If you go to View>Output it will show what it printed. Could you say what it printed.

When I remove “1” or change to “0”, makes it worse, and if I change “Linear” to “Quad” or “Sine” it doesn´t make smoother.

Do you know how to check the Output? Seeing the prints would help gather more information so we can help you.

The roblox health bar doesn’t do any tweening. This is a simple fix by changing the time it takes from 1 to something like 0.2.

The Tweening isn’t the problem, it’s that it’s changing the health bar to the wrong size. The HealthChange variable must be wrong somehow.

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))

1 Like

Remember to mark the comment that answered your question the Solution.

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.

3 Likes

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).