Gui buttons wont close but it opens

So I was making a button for my game and it won’t close but it opens and I want the buttons to close whenever a player presses the button but it wont close the gui

Video:

and here is the script I am using to make this

local frame = script.Parent.Parent.Parent.GamepassShopUI
local frame2 = script.Parent.Parent.Parent.RebirthUI
local frame3 = script.Parent.Parent.Parent.CodesUI
local frame4 = script.Parent.Parent.Parent.SkinsUI
local open = false

script.Parent.MouseButton1Click:connect(function()
	if frame4 and frame3 and frame.Visible == false then
		frame2.Visible = true 
		print("Openned")
	else
		if frame2.Visible == true then
		frame4.Visible = false
		frame3.Visible = false
		frame2.Visible = false
		frame.Visible = false
		print("closed")
	end
end)

you are setting frame2 visible to true, then when you click again, all those other frames are still not visible, so you set frame2 visible to true, again.

also,

what this is doing is not what you think it does, it is more like

if frame4 --so if it does not == false or nil
if frame3 --so if it does not == false or nil
if frame.Visible == false --so if visible == false

--you need to do

if frame4.Visible == false and frame3.Visible == false and frame.Visible == false
1 Like

If i set both frame2 as true won’t that just keep it open to the gui but not close it?

local gamepassShopUi
local gamepassShopButton

gamepassShopButton:MouseButton1Click:Connect(function()
    if gamepassShopUi.Visible == false then
        gamepassShopUi.Visible = true
    else
        gamepassShopUi.Visible = false
    end
end)

don’t copy and paste this code, just use this as an example

You should not be using script.Parent.Parent etc to index GUIs. You should do this.

local LocalPlayer = game.Players.LocalPlayer
local PlayerGui = LocalPlayer.PlayerGui -- This is basically the same as StarterGui service.

You are also missing an end.

		if frame2.Visible == true then
		frame4.Visible = false
		frame3.Visible = false
		frame2.Visible = false
		frame.Visible = false
		print("closed")