Something wrong with my admin script

I have this admin script and it is supposed to open a gui when a player chats a command. In case you didn’t know, the admin command is !adminconsole.

local Admins = {
	"bootsareme"; 
	"shoesareme"; 
}
local Prefix = "!"

local Players = game:GetService("Players")

local Commands = {}

Commands.adminconsole = function(Sender, Arguments)
	game.Players[Sender.Name].PlayerGui.AdminConsole.Enabled = true
end

local function IsAdmin(Player)
	for _,Admin in pairs (Admins) do
		if type(Admin) == "string" and string.lower(Admin) == string.lower(Player.Name) then
			return true
		elseif type(Admin) == "number" and Admin == Player.UserId then
			return true
		end
	end
	return false
end

local function ParseMessage(Player,Message)
	Message = string.lower(Message)
	local PrefixMatch = string.match(Message,"^"..Prefix)
	
	if PrefixMatch then
		Message = string.gsub(Message,PrefixMatch,"",1)
		local Arguments = {}
		
		for Argument in string.gmatch(Message,"[^%s]+") do
			table.insert(Arguments,Argument)
		end
		
		local CommandName = Arguments[1]
		table.remove(Arguments,1)
		local CommandFunc = Commands[CommandName]
		
		if CommandFunc ~= nil then
			CommandFunc(Player,Arguments)
		end
	end
end

Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message,Recipient)
		if not Recipient and IsAdmin(Player) then
			ParseMessage(Player,Message)
		end
	end)
end)

I chat the command and it opens up the GUI fine. Once I close the gui, and I proceed to type the command again, the chat stops working. Here is my chat:

bootsareme: !adminconsole --admin gui opens up
bootsareme: !adminconsole --chat for the second time, nothing happens, no errors

That basicaclly describes the problem. I don’t know what is wrong because there are no errors.

3 Likes

Use localscripts to handle gui. To open the gui, fire a remotevent to the client and on the client set up a function when it is fired. Example:

game.ReplicatedStorage['test event']:FireClient(Sender)

and on the client:

game.ReplicatedStorage:WaitForChild("test event").OnClientEvent:Connect(function()
-- do stuff
end)

You are only ever setting the AdminConsole.Enabled to true. You want to to be Enabled or Disabled based on it’s current state. If enabled, make disabled and if disabled make enabled. This would even work if you closed it with a close button rather than using the command. You should also use what @TheWorstOne_2 and tell the Client to enable/disable it.

game.Players[Sender.Name].PlayerGui.AdminConsole.Enabled = not game.Players[Sender.Name].PlayerGui.AdminConsole.Enabled

I have a close button…

Right, but what I was trying to explain is even with the close button the line of code I gave at the bottom would still work. Instead of checking if the console is enabled or not, it just switches the .Enabled value to the opposite (false to true OR true to false) without ever doing if console.Enabled == true then console.Enabled = false end. Sorry for the misunderstanding.