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)