How to get Frame to its original size

For example, when a button is clicked, the frame will expand 0,100,0,100.
when clicked again, the frame will become the original side.

how do I make it use the original side variable,
without having to write the size before 0,100,0,100

butto = script.parent
OriSize = butto.Size

butto.MouseButton1Click:Connect(function()
butto.Size = UDim2.new(0, 50,0, 50)
wait(1)
butto.Size = UDim2.new(OriSize)
end)

I’m assuming OriSize is defined out of the click function as something like local OriSize = butto.Size? If so then simply doing butto.Size = OriSize will work fine, as OriSize is already a UDim2 value.

2 Likes

its not working for me
mainpoint after the button clicked it sized to 100 and wait(1), it revert to its original size(before get cliccked)

1 Like

You need to save the original size before you start anything so I would say

local OriSize = (butto.Size)
butto.MouseButton1Click:Connect(function()
butto.Size = UDim2.new(0, 50,0, 50)
wait(1)
butto.Size = UDim2.new(OriSize)
3 Likes

thanks, but still :blush: after clicked its not revert back to its ori size

1 Like

is the code snippet you sent in the original post the full script? Because the function is missing an end) statement, which would be causing an error. Alongside missing local before defining button and OriSize.

3 Likes

Yeah thats what I was going to say also.

1 Like

I figured out a problem. I think you need to save the position too I tested it out and it totally resized in a different spot.

3 Likes

yea yright its more like need a var to save the previous size before it got clicked, but its just idk how :skull:

full script, yea just this

butto = script.parent
OriSize = butto.Size

butto.MouseButton1Click:Connect(function()
butto.Size = UDim2.new(0, 50,0, 50)
wait(1)
butto.Size = UDim2.new(OriSize)
end)
3 Likes

Just create a attribute on the part, and copy-paste the part’s size over their. You can name it whatever you want, I’d name it something like “DefaultSize”, and then in the script just reference it:

butto.MouseButton1Click:Connect(function()
butto.Size = UDim2.new(0, 50,0, 50)
wait(1)
local OriginalSize = butto:GetAttribute("DefaultSize")
butto.Size = UDim2.new(OriginalSize)
end)
3 Likes

ive tried and still, why doesnt it wok i wonder why :confused:

1 Like

Simply remember what the frames original size was and set it to that. You can just comment on the script like:

–frame size is 1,0,0,5,9,2 (or whatever)

Then just simply set it back to that

1 Like

Okay, I finally figured it out. First move your button to the middle of the screen. Then set your anchor point to 0.5. Move your button back to where it was. Add an attribute that is called “size”. The contents of that should be the size without the brackets “{}” Now that you have done that, you add your script.

local butto = script.Parent
butto.MouseButton1Click:Connect(function()
	local size = tostring(butto:GetAttribute("size"))
	local split = string.split(size,',')
	butto.Size = UDim2.new(0, 50,0, 50)
	wait(1)
	butto.Size = UDim2.new(split[1],split[2],split[3],split[4])
end)

It should work, I tested it.

1 Like

Just create an attribute for the original size and then expand to it

local button = script.Parent
button:SetAttribute(“Size”,button.Size)
button.Activated:Connect(function()
   button.Size = UDim2.new(0,50,0,50)
   wait(1)
   button.Size = button:GetAttribute(“Size”)
end)

the problem is the size is already a udim2, so making it a udim2 again causes issues