Resizing frame not working

local incriment = tonumber(game.Players:FindFirstChild(char.Name).PlayerGui.healthGui.barHandler.backgroundBar.Size.X.Scale) / maxHealth
local healthBar = game.Players:FindFirstChild(char.Name).PlayerGui.healthGui.barHandler.healthBar
local size = incriment * seat.Parent.health.Value
healthBar.Size = UDim2.new(size, 0, healthBar.AbsoluteSize.Y, 0)

Im trying to change the x size of a frame but when I try resizing it the y axis is messed up,
BEFORE:


AFTER:

I tried using absolute size of the frame for the y axis when I change the size but it still didn’t work, there was also a ui aspect ratio constraint parented to the frame so I tried removing it, change the size, the put it back, but I got the same result. Since I was changing the script in a server script, I realized that the Absolute Size part I tried using might have got confused because its in a server script, so I rerouted the same script but to a local script but I still got the same result. Any ideas on how to not make the green bar y size smaller than normal?

healthBar.Size = UDim2.new(size, 0, 1, 0)

?

Can you show me your explorer?

local incriment = tonumber(game.Players:FindFirstChild(char.Name).PlayerGui.healthGui.barHandler.backgroundBar.Size.X.Scale) / maxHealth
local healthBar = game.Players:FindFirstChild(char.Name).PlayerGui.healthGui.barHandler.healthBar
local size = incriment * seat.Parent.health.Value
healthBar.Size = UDim2.new(size, 0, 1, 0)

Using the GUI Element’s absolute sometimes does not work. I would recommend using the number 1. It is also shorten.

AbsoluteSize is represented by a Vector2 value of which its components are values in pixels (use a measurement of pixels), the first and third components of a UDim2 value correspond to its X scale and Y scale values respectively, these values represent a distance (size) as a percentage, i.e; UDim2.new(0.5, 0, 0.5, 0) would represent an area that is half of the screen’s size.

If you want to maintain the GuiObject’s current Y dimension size, I’d recommend just doing the following.

healthBar.Size = UDim2.new(size, 0, healthBar.Size.Y.Scale, 0)

Sorry it took long to reply, I was up at a late hour trying to solve the problem. This was my original method, but it did not work, I got the same result as the after picture, so I thought the scale was different because of the users screen size, so that’s why I suppose using absolute size, which is what like you said, is a vector 2 representing the pixels.

Screen Shot 2022-06-08 at 10.17.05 AM
as you see it cannot work by using 1 because health bar, the green bar, is parented the the bigger bar you see, (the background bar is the red bar behind the green bar, bar handle is the gray-see through bar).

this also answers your question, up above ^

UDim2.new(size, 0, 0, healthBar.Size.Y.Offset)

You may need to do this instead (if the bar is sized using offset values as opposed to scale values).

I have a new Idea of organizing the gui to make it easier to script. Instead I’ll parent the health bar to background bar so I can change the bar y size to 1, and then change the width normally.

Nope, I tried the method I suggested to myself but I achieved the same result as the after image. I’ll try yours right now.

My image is sized by using scale, so when I tried this my entire bar turned red, because my offset y value is 0.

I had to go out with a unsatisfying ending. I had to remove the UI constraint. It would still look good, but not as good as it did before, at least now it functions. Thank you for your guys’s help, your still free to help me out if you want, im happy to revert back to ui aspect ratio constraint and just use a different sizing method, I’ll changed my solved to yours.

hey, so don’t worry guy! There’s a solution but you need to use TweenService!

local Sizer = 1 -- This is the size of the bar, so try to change this to your liking..

Bar:TweenSize(UDim2.new(1.013/(humanoid.MaxHealth/math.floor(humanoid.Health + .5)),0,1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, .25)

It’s not exactly the solution you wanted, but in my opinion using tweens makes the visual look prettier!