How would I detect if a gui size is larger than a specific size?

I’m trying to prevent a gui from becoming too big with an if statement, but it doesn’t seem to work.

--I've tried this method already, but it didn't do anything. Not even an error.
if gui.Size > [specific size] then
    gui.Size = [specific size]
end

Could anyone help me?

What do you want to use this for? It’s probably better to grow towards a specific size (e.g. with a tween), and then do what you want once that is finished (e.g. with tween.Completed).

To answer your actual question though:

Compare the actual components of the Size, like .Size.X.Offset or .Size.X.Scale.

If you just want to deal with pixels and not scale+offset, you can use .AbsoluteSize.X and .AbsoluteSize.Y instead.

1 Like

the size will never change but the absolute size would i think

--Is this what you mean? because I tried this and it did not work.
if script.Parent.Size.X.Scale > 717 then
	script.Parent.Size.X.Scale = 717
end

Well, a Scale of 717 would mean “717x wider than the screen”, which is probably not what you mean.

You probably want AbsoluteSize or X.Offset like I mentioned.

What are you using this for?

Do not use .Size, use .AbsoluteSize

Sorry for the late response, but I’m using it for a gui which size depends on a value, like a stamina bar. I increase the value by 20 and sometimes the gui goes over the max stamina. If staminabar is over > size then it changes its size back to the original.

The bug seems to be in the way you’re modifying the gui’s to match the value then—you should fix that part of the code instead.

Can you share the code you use to tie the gui size to the value?

Can you also share the code where you’re changing the value, with a description of what you intend it to do?

1 Like