Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does this frame size up and down script not work?

currently i am making an gui that gets big and small with the same button this is what i mean a button, if you press on that button the frame gets big and, if you do it again it gets smaller very basic.

My code:

local frame = script.Parent.Parent.Parent



script.Parent.MouseButton1Click:Connect(function()
	if frame.Size==frame.Size then
		frame.Size = UDim2.new(1,0,1,0)
		frame.Position = UDim2.new(0, 0,0, 0)

	else
		frame.Size = UDim2.new(0, 1084,0, 673)
		frame.Position = UDim2.new(0.5, -542,0.537, -336)
		

	end

end)

it makes the gui bigger but dose not make it smaller how would i fix it?

1 answer

The reason it never gets smaller is because if frame.Size == frame.Size is always true. This means that it will never reach the else. To fix this, use a boolean indicating it's current size.

local frame = script.Parent.Parent.Parent

local big = false

script.Parent.MouseButton1Click:Connect(function()
    if not big then
        frame.Size = UDim2.new(1,0,1,0)
        frame.Position = UDim2.new(0, 0,0, 0)
		big = true
    else
        frame.Size = UDim2.new(0, 1084,0, 673)
        frame.Position = UDim2.new(0.5, -542,0.537, -336)
		big = false
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.