Admin Commands Bug

I have this admin command script and everytime a player chats, it says “You do not have permission to chat.” That is the remote event (dont worry that is working). I cant seem to figure out why, but no matter what they say, for example, “hello” its not even a command, but it still fires that remote event.

local Admins = {
	"bootsareme";
}

local Prefix = "!"
local Players = game:GetService("Players")
local Commands = {}

Commands.console = function(Sender)
	game.ReplicatedStorage.OpenAdminConsole:FireClient(Sender)
end

Commands.warn = function(Sender, Arguments)
	local success, fail = pcall(function()
		local username = Arguments[1]
		table.remove(Arguments, 1)
		local message = table.concat(Arguments, " ")
		game.ReplicatedStorage.SendSysNotification:FireClient(Players[username], message)
	end)
	if fail then
		game.ReplicatedStorage.PostSystemMsg:FireClient(Sender, "An error occurred: the player specified was not found.")
	end
end

Commands.kick = function(Sender, Arguments)
	local success, fail = pcall(function()
		local username = Arguments[1]
		table.remove(Arguments, 1)
		local message = table.concat(Arguments, " ")
		Players[username]:Kick(message)
	end)
	if fail then
		game.ReplicatedStorage.PostSystemMsg:FireClient(Sender, "An error occurred: the player specified was not found.")
	end
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)
	
	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)
	if Player:GetRankInGroup(5474151) >= 253 then
		table.insert(Admins, Player.Name)
	end
	Player.Chatted:Connect(function(Message, Recipient)
		if not Recipient and IsAdmin(Player) then
			ParseMessage(Player,Message)
		else
			game.ReplicatedStorage.PostSystemMsg:FireClient(Player, "You do not have permission to use this command.")
		end
	end)
end)

The event that tells the player that you cant use this command fires if you aren’t an admin at all and you are normally chatting.

Even if you are just normally chatting it still fires.

By the way assuming you are putting your commands in one script, I suggest making a module then importing the commands from there instead. It makes it way easier to edit and read.

How would I check if the player is only chatting the command?

You could have the parse message command return false if the command they are trying to run doesnt exist.

If they are only chatting the command, it should return true.

You will need to check if the message starts with the prefix, and if not, ignore the message completely.

You can just do this:

if string.sub(Message, 1, string.len(Prefix)) == Prefix then

Please let me know if it doesn’t work, since I have not tested it yet.