How to make a bar scale from the center

I’m trying to make a bar scaling from the center. If you don’t understand, I mean sort of like this effect:

100% = image

50% = image

and 0% = image

How would I go about calculating size? The position was the easy part.

1 Like

When I did something similar when you tween the bar to make it smaller, also tween the bar close to the centre, it would need so maths but it works well.

For position, AnchorPoint will make life easy for you! Set the AnchorPoint to 0.5, 0.5 then set the Position to 0.5, 0, 0.5, 0. Then all you have to do is change the size of X between 0 and 1, no fancy math needed!

Here’s the calculation for health:

Humanoid.HealthChanged:Connect(function(health)
 local amount = health/Humanoid.MaxHealth --This is a number between 0 and 1
 Bar.Size = UDim2.new(amount,0,1,0) --Alternatively you could tween to this value!
end
4 Likes