Error with admin script on Line 15

I wanted to add custom admin commands to my Roblox game, so I went on google and looked up “how to make admin commands on Roblox” so I can mess with player’s cash amounts if I need to on mobile. I found this DevForum post in Community Tutorials from Google, but, I get this error when trying to use my addmoney command:
The command I’m trying to do is: !addmoney OldBo5 100000

12:48:53.177 - ServerScriptService.Admin:15: bad argument #2 to '?' (string expected, got table)
12:48:53.178 - Stack Begin
12:48:53.179 - Script 'ServerScriptService.Admin', Line 15 - local CommandFunc
12:48:53.180 - Script 'ServerScriptService.Admin', Line 58 - upvalue ParseMessage
12:48:53.180 - Script 'ServerScriptService.Admin', Line 66
12:48:53.181 - Stack End

Here is my code:

local Admins = {
	129415482; -- User ID of OldBo5
}
local Prefix = "!"

local Players = game:GetService("Players")

local Commands = {}

Commands.print = function(Sender,Arguments)
	local Message = table.concat(Arguments," ")
	print("From " ..Sender.Name..":\n"..Message)
end
Commands.addmoney = function(Sender, PlayerGiven, Cash)
	game.Players[PlayerGiven].leaderstats.Money.Value = game.Players[PlayerGiven].leaderstats.Money.Value + Cash
end
Commands.removemoney = function(Sender, PlayerGiven, Cash)
	game.Players[PlayerGiven].leaderstats.Money.Value = game.Players[PlayerGiven].leaderstats.Money.Value - Cash
end
Commands.setmoney = function(Sender, PlayerGiven, Cash)
	game.Players[PlayerGiven].leaderstats.Money.Value = Cash
end

local function IsAdmin(Player)
	for _,Admin in pairs (Admins) do
		print(Admin,Player)
		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 or 1) 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 = {}
		
		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)
1 Like

Instead of doing

CommandFunc(Player,Arguments)

Try doing

CommandFunc(Player, unpack(Arguments))

Unpacking the arguments will result in receiving each piece of data as separate variables, so instead of an argument table, you’ll get the variables you expect.

This may mess with the code you have with Commands.print, so I suggest changing it to:

Commands.print = function(Sender,...) -- ... represents the arguments that are sent
	local Message = table.concat({...}," ")
	print("From " ..Sender.Name..":\n"..Message)
end
1 Like

I am now getting:

  129415482 OldBo5
  13:22:09.600 - oldbo5 is not a valid member of Players
13:22:09.601 - Stack Begin
13:22:09.601 - Script 'ServerScriptService.Admin', Line 15 - local CommandFunc
13:22:09.602 - Script 'ServerScriptService.Admin', Line 58 - upvalue ParseMessage
13:22:09.603 - Script 'ServerScriptService.Admin', Line 66
13:22:09.604 - Stack End

Looks like you made it lowercase.

1 Like

I didn’t make the command lowercase.
!addmoney OldBo5 100000

You didn’t type it lower case, your script made it. image

1 Like

It works now! Thanks alot. :smiley:

1 Like

An alternative could be to keep the lowercasing but instead of checking Players directly for a player, lowercase the player’s name as well. Bad overhead and not a great idea but it works.

1 Like