--local function GetSameItem(instance)
--	for i,v in pairs(Main) do
--		if v==instance then 
--			return v
--		end
--	end
--end


local function HideAllFrames()
	for i,v in pairs(Main) do
		v.Visible=false
	end
end

local function ToggleVisibility(Element)
	local vis=Element.Visible
	HideAllFrames()
	if vis==true then return end
	if Element.Visible==true then
		Element.Visible=false
	elseif Element.Visible==false then
		Element.Visible=true
	end
end

for i,v in pairs(SettingsOpener:GetDescendants()) do
	if v:IsA("GuiButton") then
		local folder=v:FindFirstAncestorWhichIsA("Folder")
		v.Activated:Connect(function()
			ToggleVisibility(Main[folder])
		end)
	end
end

for i,v in pairs(ShopOpener:GetDescendants()) do
	if v:IsA("GuiButton") then
		local folder=v:FindFirstAncestorWhichIsA("Folder")
		v.Activated:Connect(function()
			ToggleVisibility(Main[folder])
		end)
	end
end

ToggleButton.Activated:Connect(function()
	ToggleVisibility(ToggleButton)
	for i,v in pairs(Main) do
		if type(i)=="userdata" then
			for s,a in pairs(i:GetDescendants()) do
				if a:IsA("GuiButton") then
					local vis=a.Visible
					if vis==true then
						a.Visible=false
					elseif vis==false then
						a.Visible=true
					end
				end
			end
		end
	end
	local caret=ToggleButton.Text
	if caret=="<" then
		ToggleButton.Text=">"
	elseif caret==">" then
		ToggleButton.Text="<"
	end
	HideAllFrames()
end)
