Health bar tweening issue

Hey.

My health bar is tweening the wrong way, it’s tweening to the middle, but it has to tween from right to left.

image

Any fix?

while wait() do

	if Player.Character.Humanoid.Health <= 25 then
		script.Parent.PlayerFrame.Health.Bar.BackgroundColor3 = Color3.fromRGB(255,0,0)
	else
		script.Parent.PlayerFrame.Health.Bar.BackgroundColor3 = Color3.fromRGB(0,255,0)
	end


	script.Parent.PlayerFrame.Health.Bar.Size = UDim2.new(0, (Char:WaitForChild("Humanoid").Health / Char:WaitForChild("Humanoid").MaxHealth * 230), 1, 0)
    --the 230 at MaxHealth * 230 means that the frame size is 230.

end

You could use :TweenSize() instead of while wait() and also use

char:WaitForChild("Humanoid").Changed:Connect(function()

Yeah, I could do that. But I don’t think that fixes the tweening itself lol

tween the position as well i guess

It would only change the position, but he wants to change the size

1 Like

Your issue is that your AnchorPoint.X value is set to 0.5, which is the ‘halfway point’ (or ‘the middle’). To fix this, set it to 0.

an unusual choice for a health bar, but let’s work with it.

Everything works from left to right. Reading, writing, in this case- tweening. To make it go backwards (right to left) you must use negative numbers. The line of code to tween your health bar should look something like this:

script.Parent.PlayerFrame.Health.Bar:TweenSize(UDim2.new(0,-(Char:WaitForChild("Humanoid").Health / Char.Humanoid.MaxHealth), 1, 0)

*also, try to refrain from using while loops for this sort of thing. Similarly to what @AridFights1 said, there are events that work perfectly for what you are trying to do. In this case, I recommend tweening your health bar when the Humanoid.HealthChanged event is fired.

1 Like

oooh! That may be the issue. My anchor point is 0.5, 0.5. Testing this now

I did an awful job at explaining, so here’s an example file to help further if you need it! :grinning_face_with_smiling_eyes:
tween example.rbxl (30.5 KB)