Ui not closing other menu when a new button is clicked

I am currently having an issue with a Ui script in my game that should be closing 1 ui when another one in the list is clicked. It was working with my other menu but I am having problems with this one now.

If anyone might know what I am doing wrong, it would be a huge help to get this figured out! Thank you!

local button = script.Parent
local clicked = false
local teams = script.Parent.Parent:WaitForChild("General")

local function onOpen()
	teams.Visible = true


end

local function onClose(ui)
	ui.Visible = false
end

button.MouseButton1Click:Connect(function()
	if clicked == false then
		onOpen()

		for i,v in pairs(script.Parent.Parent.Parent.Parent.QCH.holder:GetChildren()) do
			if v.ClassName == "Frame" then
				if v.Name ~= "General" then
					if v ~= teams then
						onClose(v)
					end
				end
			end
		end

		clicked = true
	elseif clicked == true then
		onClose(teams)
		clicked = false
	end
end)

image

I’m not the best scripter and my knowledge of bug fixing is not all there, so I’ve been struggling with this for almost 2 hours.

Something like this should open and close frames with buttons:

close frame with x:

script.Parent.MouseButton1Click:connect(function() -- Most likely X button in frame
script.Parent.Visible = true
end)

(?)frame menu:

script.Parent.MouseButton1Click:connect(function() -- Most likely button to open frame
script.Parent.FrameName.Visible = true
end)