GUI only enables once

Basically, I have this GUI that opens when you use a command. When you press the close button, it works fine. But when you try opening it again, it doesn’t work.

Code:

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg == openCommand then
			if plr:GetRankInGroup(groupID) >= minRank then
				plr.PlayerGui.adminPanel.Enabled = true
			end
		end
	end)
end)

This code looks OK, could you show the close button’s code?

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Parent.Enabled = false
end)

Is this indexing the right Gui? you might be disabling the parent of the adminpanel Gui.

Yeah, I just checked and it is right.

Try this out.

game.Players.PlayerAdded:Connect(function(plr)
    local adminPanel = plr.PlayerGui.adminPanel
	plr.Chatted:Connect(function(msg)
		if msg == openCommand then
			if plr:GetRankInGroup(groupID) >= minRank then
                if not adminPanel.Enabled then 
                    adminPanel.Enabled = true 
                end 
			end
		end
        if msg:lower() == "close" then 
			if plr:GetRankInGroup(groupID) >= minRank then
				adminPanel.Enabled = not adminPanel.Enabled
			end
        end 
	end)
end)

Yeah, but I would not like a command to close it.

The problem is that you’re opening it on a server script and closing it on a local script. To keep a good practice, ALL gui handling should be handled on local scripts as much as possible.

Bro wants him to handle admin commands on the client :skull:

What’s wrong with handling GUI on server scripts? It still works.

We are going off topic, I am asking how do I fix the issue of it only opening once.

Just put the mousebuttonevent in the playeradded with the code i did.

Why are you using Enabled anyway? Chances are, there is a single frame with the GUI in it. Why not change Frame.Visible?

Theres nothing wrong with what he is doing. Same result.

Well, my GUI does not have a single frame, so…

Just take the code from mine and put it inside of the playeradded event inside of a mousebutton1down event.

I will just try firing the client on a remote event, I’ll see if that works. Since the other guy said it messes things up if one is on the server and one is on the local.

You can just handle it all on the server. Either handle it all on the client or handle it all on the server.

Paste this in your close button script:

local player = game.Players.LocalPlayer
local closeBtn = script.Parent

local openCommand = "CHANGE ME"
local groupID = 1234567890 --change to group id
local minRank = 123 --change to min rank

player.Chatted:Connect(function(msg)
    if msg == openCommand then
        if plr:GetRankInGroup(groupID) >= minRank then
            player.PlayerGui.adminPanel.Enabled = true
        end
    end
end)

closeBtn.MouseButton1Click:Connect(function()
    player.PlayerGui.adminPanel.Enabled = false
end)

As far as I can remember when we disable Enabled scripts don’t run. That’s why I said that. If that’s the case, could that be the problem?