Frame goes over the certain size limit

robloxapp-20220422-1451535.wmv (396.0 KB)

the progress bar goes over the size limit here is the script

local ClickArea = script.Parent.Parent.Parent.Parent.ClickArea
local sound  = script.Parent.Parent.Parent.Parent.Sound
local progress = script.Parent

ClickArea.MouseButton1Click:Connect(function()
	sound:Play()

	if progress.Size == UDim2.new(0,562,0,28) then
		progress:Destroy() return end
	progress.Size += UDim2.new(0,70.25,0,0)
end)

any help will be appreciated

2 Likes

The condition will never be met cause you’re not adding to the Y axis.

local x_max = 562
local x = math.clamp(progress.Size.X.Offset+=70.25,0,x_max)
progress.Size = UDim2.new(0,x,1,0) -- have the Y scaled at 1 for this scenario
if progress.Size.X.Offset == x_max then
    progress:Destroy()
end
1 Like

it’s better to do less an "<" rather than equal to "=" otherwise the script will exceed the limit
edit: oops my bad you should do greater than ">", and also adds the guy above me

sorry for the long reply but it dosent work it gives me this error in the output
attempt to compare UDim2 < UDim2

1 Like

You can’t compare the two. try doing something like:

if progress.Size.X.Offset >= 562 then

end
1 Like

yeah, looking back at what he was trying to do, not just his code (which was confusing) he was trying to make a progress bar, which adding to the Y is not needed so your solution should suffice.

It is a questionable way to do it but I’m not going to judge.

There is a UI constraint for this. It is called UISizeConstraint

Your issue is really that it’ll never see the size limit.
You made it compare to see if two UDim2 values are equal to each other, that’s three different values!
What you should do is replace this line:

With this one


What you should do is replace this line:

if progress.Size.X.Offset >= 562 then

UDim2’s are just two UDim values, and UDim values are just one offset value and one scale value
The names to the UDim2’s properties are “X” and “Y”, but the names to UDim’s properties are “Scale” and “Offset”. You can read up and Offset and Scale here.
Let me know if you are having any other troubles!