Health Bar is not set correctly

Hi,
I have a health bar but the scale is not set correctly

here the health is full:
image

here the health is only 60% and the bar is already below 50%:

here is the function:

local function SetProgress(health, maxHealth)
	local heal = math.clamp((health / maxHealth),0,1)
	if health == 0 then
		heal = 0
	else
		heal = math.clamp((health / maxHealth),0,1)
	end

	print(heal)
	
	local T1 = game:GetService("TweenService"):Create(Base.BgFrame,TweenInfo.new(0.2,Enum.EasingStyle.Sine, Enum.EasingDirection.Out),{Size = UDim2.fromScale(heal,1)})
	local T2 = game:GetService("TweenService"):Create(Base.BgFrame.Health,TweenInfo.new(0.2,Enum.EasingStyle.Sine, Enum.EasingDirection.Out),{Size = UDim2.fromScale(heal,1)})
	T1:Play()
	T2:Play()
end

I also noticed that if i added 0.2 to the heal it will be sized correctly but after 70%
it stays looking full if the health is 100% or 90% or 80%.

4 Likes

is the frame that fills in the bar bigger than it needs to be? that could be the issue

frame and the health image are the same exact size UDim2.new(1,0,1,0)

i mean is like the frame containing the bar bigger than the actual part inside?
image
the image frame could be covering up the sides of the bar

2 Likes

well actually no, it works well when i added 0.2 to both of their sizes but that also breaks the bar if the health between 100 and 80
image

what’s T1? your setup could be different, but I think u should only be tweening T2

you should only be tweening the health bar

2 Likes

actually this fixed the problem thank you

Edit: Tween any of them (Can be the frame or the image) fixes it, Tweening both of them didn’t work

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.