Closing other GUIs when a GUI is opened

I’m trying to close other unnecessary GUIs when a GUI is opened. But it doesn’t work. Is there something I overlooked?

local buttonsGui = script.Parent.Parent.Buttons
local petsButton = buttonsGui.LeftButtonHolder.Pets

local Players = game:GetService("Players")

local player = Players.LocalPlayer

local screenGui = script.Parent

petsButton.MouseButton1Click:Connect(function()
	screenGui.Enabled = not screenGui.Enabled
	
	for i , v in pairs(player.PlayerGui:GetChildren()) do
		for i,c in pairs(v:GetChildren()) do
			if c:IsA("ScreenGui") then
				if c.Name == ("CurrencyGUI") then
				elseif c.Name == ("Buttons") then
				elseif c.Name == ("PetInventory") then
				else
					c.Enabled = false
				end
			end
		end
	end
	
end)```
1 Like

The code looks fine, are you sure the button is able to be clicked? Try adding a print statement when the user clicks the button to see if that function is triggered.

Actually now that I look at it, if the GUIs are stored directly in the PlayerGUI then the second for loop isn’t necessary.

2 Likes

yes that’s the problem thanks.When I removed the second for loop from the code it started working

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.