Chat Admin Commands

yes, can i add that in the main script instead of individually?

You can just put 1 player finder function at the top of the module script, and inside the module script commands you could do like

local victimPlayer = FindPlayer(victim)

^^ instead of victim:Kick() it would be victimPlayer:Kick()

now this wont print

if CommandFunc ~= nil then
			print (CommandFunc)
			CommandFunc(Player,unpack(Arguments))
		end
local Admins = {
	"Player1"; -- Username example
	"Player2"; -- Username example

	{GroupId = 4525406;
		RankId = 250;} -- Group example
}

local Prefix = ":"

local Players = game:GetService("Players")

local commandModule = require(script.Commands)

commandModule.print = function(Sender,Arguments)
	local Message = table.concat(Arguments," ")
	print("From " ..Sender.Name..":\n"..Message)
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
		elseif type(Admin) == "table" then
			local Rank = Player:GetRankInGroup(Admin.GroupId)
			if Rank >= Admin.RankId then
				return true
			end
		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 = string.split(Message, " ")


		local CommandName = Arguments[1]
		table.remove(Arguments,1)
		local CommandFunc = commandModule[CommandName]
		local splittedString = string.split(Message," ") 
		print(Player, Arguments[1])
		if string.sub(splittedString[2]:lower(),1) == 
			string.sub(Arguments[1]:lower(),1,splittedString[2]:len()) then 
			print("Found") 
		end    		

		if CommandFunc ~= nil then
			print (CommandFunc)
			CommandFunc(Player,unpack(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)```

Don’t remove that, you still need that to delete the prefix from the message

1 is underlined, says “argument count mismatch”

Can you send a screenshot of that and the code around it

1 Like

https://gyazo.com/936a45fab15ec020131e2e29258e5452?token=deafbe4501ea69de4b29caca1348a209

Um, was it doing that before? I copy pasted your code and it looks identical and there aren’t any kind of errors.
Also, you sent the gyazo link with your auth tokenimage

No it didn’t, i’m not sure why it is now
https://gyazo.com/936a45fab15ec020131e2e29258e5452

You should snip the auth token, it can be used to upload images on your account I’m pretty sure

This is the code I have idk why it shows that you have the incorrect number of arguments

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 = commandModule[CommandName]

		if CommandFunc ~= nil then
			CommandFunc(Player,unpack(Arguments))
		end
	end
end

idk how

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 = string.split(Message, " ")


		local CommandName = Arguments[1]
		table.remove(Arguments,1)
		local CommandFunc = commandModule[CommandName]
		local splittedString = string.split(Message," ") 
		print(Player, Arguments[1])
		if string.sub(splittedString[2]:lower(),1) == 
			string.sub(Arguments[1]:lower(),1,splittedString[2]:len()) then 
			print("Found") 
		end    		

		if CommandFunc ~= nil then
			print (CommandFunc)
			CommandFunc(Player,unpack(Arguments))
		end
	end
end

Try removing the line with string.split and use the old arguments thing from before, idk what’s going on Lol

still happens

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 = commandModule[CommandName]
		local splittedString = string.split(Message," ") 
		print(Player, Arguments[1])
		if string.sub(splittedString[2]:lower(),1) == 
			string.sub(Arguments[1]:lower(),1,splittedString[2]:len()) then 
			print("Found") 
		end    		

		if CommandFunc ~= nil then
			print (CommandFunc)
			CommandFunc(Player,unpack(Arguments))
		end
	end
end```

Try replacing the whole script with this idk, it works for me

local Admins = {
	"Player1"; -- Username example
	"Player2"; -- Username example
	112896842;
	{GroupId = 4525406;
		RankId = 250;} -- Group example
}

local Prefix = ":"

local Players = game:GetService("Players")

local commandModule = require(script.Commands)

commandModule.print = function(Sender,Arguments)
	local Message = table.concat(Arguments," ")
	print("From " ..Sender.Name..":\n"..Message)
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
		elseif type(Admin) == "table" then
			local Rank = Player:GetRankInGroup(Admin.GroupId)
			if Rank >= Admin.RankId then
				return true
			end
		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 = string.split(Message, " ")

		local CommandName = Arguments[1]
		table.remove(Arguments,1)
		local CommandFunc = commandModule[CommandName]
		local splittedString = string.split(Message," ") 
		print(Player, Arguments[1])
		if string.sub(splittedString[2]:lower(),1) == 
			string.sub(Arguments[1]:lower(),1,splittedString[2]:len()) then 
			print("Found") 
		end    		

		if CommandFunc ~= nil then
			print (CommandFunc)
			CommandFunc(Player,unpack(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)

:confused: still doesn’t work…

Try restarting studio? Or launching the game and see if it works anyway?

“Function expects 3 arguments, but there are 4”

Ok, instead of

Message = string.gsub(Message,PrefixMatch,"",1)

try

Message = string.sub(Message, string.len(Prefix) + 1)

ok, that works. now this is just printing " " nothing.

print (CommandFunc(Player,unpack(Arguments)))