How to do this?

Hey guys. I’d like to know how I can prevent my frame from going “out of bounds”. If you don’t know what I mean, take an HP bar for example. You have the bar that indicates how much HP the player has, and the background which indicates how much HP the player is missing. That’s basically what I want, but because of the way the bar is scaled, it isn’t as easy to do. Sincere thanks if you decide to help me! Here’s my current code.

KRBar:GetPropertyChangedSignal("Size"):Connect(function()
	KRBar.Position = UDim2.fromScale(-KRBar.Size.X.Scale / 2 + 1, KRBar.Position.Y.Scale)
end)

Screenshot 2023-09-11 160506
Hopefully this screenshot helps. Obviously the frames are inside of a ScreenGui.

Video: robloxapp-20230911-1624347.wmv (818.0 KB) (Recently added)

Just change the horizontal/verticale Scale property of the foreground bar as a ratio of the player’s current health to their maximum health, or whatever value you’re measuring:

Udim2.new(health / maxHealth, xOffset, yScale, yOffset) -- horiztonal
Udim2.new(xScale, xOffset, health / maxHealth, yOffset) -- vertical

You’ll have to apply that ratio to whatever scaling you are using. Just multiply whatever the scale is by that ratio and it should scale accordingly. If not, you may have to do some math trickery to make it work properly.

2 Likes

robloxapp-20230911-1624347.wmv (818.0 KB)
So sorry if the quality is trash. This is what is happening though.

Enable clip descendants in the main frame.

1 Like

Thanks. This helped! Can’t believe it was that simple. :melting_face:

1 Like

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