Help with Health Bar

Me and my friend were trying to make a healthbar script, but currently it shrinks from the right, while I need it to shrink from the left. I need this code to shrink from the opposite direction it shrinks from currently, any help?

local player2gui = player2:WaitForChild("PlayerGui")

local p2HealthBack = player2gui:WaitForChild("Gameplay"):WaitForChild("Match"):WaitForChild("Health Bars"):WaitForChild("Player2"):WaitForChild("HealthBack")
local healthBar = p2HealthBack.Health

local endSize = UDim2.new((Health / 100), 0, 1, 0)
local endPos = UDim2.new((Health / 100) / 2, 0, .5, 0)

healthBar:TweenSizeAndPosition(endSize, endPos, "In", "Exponential", 0.25, true, nil)
1 Like

Can I see a screenshot of the properties? Changing the anchor point of the bar to 1,0 and the position to 1,0,0,0 will make it shrink from the left.

1 Like

Changing it to 1, 0.5 and 1, 0, 0.5, 0 also works
(Do either of the two in the properties of the object, not via script. It’s a lil better that way)

1 Like

Heres the properties:
Screen Shot 2023-01-09 at 8.20.07 PM
Screen Shot 2023-01-09 at 8.20.29 PM

I tried the way you said it didn’t work it did something weird but heres the gui; the arrow is the direction I want the bar to tween

Changing the orientation to 180 might work. Try that before anything else. If that doesn’t work:

Are you able to provide a video? It should work, but maybe it is with the code. I doubt it, but maybe I guess. Can you provide the code for me, please?

Flip the UI’s Orientation to 180

UI.Rotation = 180

This is a simple way of doing irt

Another way would be to have a UIConstraint Keeping the UI in place

1 Like

Btw, can you click on the Edit icon and Send a Screenshot?
Just to check when this was last edited

On god I didn’t see your reply until after. My bad lol :skull::skull::skull:
I had my glasses off. I couldn’t read anything you said

Sure.

Sure.

Me with 5/20 vision and my glasses on my night stand:

I just want to see when this was last edited, you know, this thing?

Thank you, that’s all I needed to know, Plus, about the about the “glasses”, that’s not really believable and off topic, I was wondering about the Last Time it was edited because if the OP looks at it, they will think you said it first.

Then what are you doing?

That’s a good reason, and I give credit to you since you said it first.

And yeah, I can see how it wasn’t believable, but it was true. Also very off topic, I agree; however, that is exactly why I don’t want to argue about it. There’s no point to :woman_shrugging:


I didn’t mean to copy your suggestion. It was by complete mistake and I apologize.

1 Like

Screen Shot 2023-01-09 at 10.53.40 PM

Heres the code: (the player2 healthbar is the one on the right, which works perfectly.) @DasKairo

player1.Character.Humanoid.HealthChanged:Connect(function(Health)
   local player1gui = player1:WaitForChild("PlayerGui")
   local player2gui = player2:WaitForChild("PlayerGui")
					
   local p1HealthBack = player1gui:WaitForChild("Gameplay"):WaitForChild("Match"):WaitForChild("Health Bars"):WaitForChild("Player1"):WaitForChild("HealthBack")
   local healthBar1 = p1HealthBack.Health
   local p2HealthBack =    player2gui:WaitForChild("Gameplay"):WaitForChild("Match"):WaitForChild("Health Bars"):WaitForChild("Player1"):WaitForChild("HealthBack")
   local healthBar2 = p2HealthBack.Health
					
   local endSize = UDim2.new(-(Health / 100), 0, 1, 0)
   local endPos = UDim2.new(-((Health / 100) / 2), 0, 0.5, 0)
					
   healthBar1:TweenSizeAndPosition(endSize, endPos, "In", "Exponential", 0.25, false, nil)
   healthBar2:TweenSizeAndPosition(endSize, endPos, "In", "Exponential", 0.25, false, nil)
end)
				
player2.Character.Humanoid.HealthChanged:Connect(function(Health)
	local player1gui = player1:WaitForChild("PlayerGui")
	local player2gui = player2:WaitForChild("PlayerGui")

	local p1HealthBack = player1gui:WaitForChild("Gameplay"):WaitForChild("Match"):WaitForChild("Health Bars"):WaitForChild("Player2"):WaitForChild("HealthBack")
	local healthBar1 = p1HealthBack.Health
	local p2HealthBack = player2gui:WaitForChild("Gameplay"):WaitForChild("Match"):WaitForChild("Health Bars"):WaitForChild("Player2"):WaitForChild("HealthBack")
	local healthBar2 = p2HealthBack.Health

	local endSize = UDim2.new((Health / 100), 0, 1, 0)
	local endPos = UDim2.new(((Health / 100) / 2), 0, 0.5, 0)

	healthBar1:TweenSizeAndPosition(endSize, endPos, "In", "Exponential", 0.25, false, nil)
	healthBar2:TweenSizeAndPosition(endSize, endPos, "In", "Exponential", 0.25, false, nil)
end)

Maybe something to do with the fact you are making the X size negative and changed the properties? “-(Health / 100)” and “-((Health / 100) / 2)”


I highly, highly doubt it. Especially since it worked before (before you changed the anchor point, position, and rotation), it just changed its size the wrong way. I’ve made something very similar before to what you have now, and it only changed size in the wrong direction. I just changed the anchor point & position that solved it for me. Same with every other health bar I’ve ever made that changes from left to right.


I would change the rotation back to 0, remove the negatives, keep the anchor point 1, 0 and the position 1, 0, 0, 0. Then make them positive, like this:

local endSize = UDim2.new((Health / 100), 0, 1, 0)
local endPos = UDim2.new(((Health / 100) / 2), 0, 0.5, 0)

Again, I highly doubt that’ll fix it; however, that doesn’t mean you can’t try. I’m just guessing random things at this point lol

I’ve never encountered your exact problem myself, so I’m more confused than anything. It’s anyways worked just fine for me.

If this doesn’t work I might not be able to help at all, because again, I’ve never had this happen to me.

I also can’t make a mock version of it to test since I’m at school on my phone currently.

Do you think it has to do with the healthbar being a child of another frame similarly shaped (the outline, it’s called HealthBack)?

I’m going to test real quick your suggestion

If the frame is the exact same, just flipped or something, it shouldn’t cause any issues at all. It should work just fine. I can’t really think of why it could be happening

But even then, changing the frame shouldn’t cause much of an issue. Normally as long as you have the anchor point the way you want it, it’s fully functional no matter the size or rotation (rotation would change the way it changes size obviously, but that isn’t really much of a change. You’d just have to change the anchor point accordingly)