Open GUI button won't work

Hello. I was making a update so there are less buttons on the side, and when I came up with this button that acesses the teleports, well, I tried to script it and it doesn’t work.

Script:

local player = game.Players.LocalPlayer -- this is useless ignore it
local button = script.Parent
local telegui = script.Parent.Parent.Parent.teleport.ScrollingFrame
local number = 0

button.MouseButton1Click:Connect(function()
	number = 1
	if number == 1 then
		telegui.Visible = true
	end
	else
	number = 0
	if number = 0 then
		telegui.Visible = false
		
	end
end)

The button thing in properties so you can understand it easier:
image

Instead of having a variable that controls whether it is visible, you can negate the Visible property; if true, it will be false.

local player = game:GetService("Players").LocalPlayer -- this is useless ignore it
local button = script.Parent
local telegui = script.Parent.Parent.Parent.teleport.ScrollingFrame

button.MouseButton1Click:Connect(function()
	telegui.Visible = not telegui.Visible
end)

I had an issue like this once, so maybe this would work:

local player = game.Players.LocalPlayer -- this is useless ignore it
local button = script.Parent
local telegui = script.Parent.Parent.Parent.teleport.ScrollingFrame
local number = 0

local function func()
   number = 1
	if number == 1 then
		telegui.Visible = true
	end
	else
	number = 0
	if number = 0 then
		telegui.Visible = false
		
	end
end
button.MouseButton1Click:Connect(func)

And like he said, it would be easier just to use telegui.Visible = not telegui.Visivble

The easiest way to achieve this would simply be checking if the Scrolling Frame is visible or not. To do this, I personally would just check if the visible property was true or false, I have left an example below.

local Player = game.Players.LocalPlayer --local player (Not really needed, I do this mainly from habit)

local Button = script.Parent --text button
local Frame = script.Parent.Parent.Parent.Frame2 --frame that I want to use

Button.MouseButton1Click:Connect(function() --function
	if Frame.Visible == false then --checking if the frame is visible or not
		Frame.Visible = true --making the frame visible if the "Visible" property is false
	else
		Frame.Visible = false --making the frame not visible if the "Visible" property is true
	end
end)

Hope this helped, there are many ways to achieve this, this is personally how I would go about it.

That’s more complicated then it should be:

local Player = game.Players.LocalPlayer --local player (Not really needed, I do this mainly from habit)

local Button = script.Parent --text button
local Frame = script.Parent.Parent.Parent.Frame2 --frame that I want to use

Button.MouseButton1Click:Connect(function() --function
	Frame.Visible = not Frame.Visible
end)

Your script still works though, it’s just this would be easier to script