Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can someone help me with a command to add a user's leaderstats? ( RE-OPENED )

So I'm getting some errors when I do < :addrp player number >

**Error ( Bad Argument #2 ), "string expected, got Object"** Error Line: 47 Error Line: 100 function parseMessage to Error Line 108

Here is my coding below:


local Admins = {
<my admins have been removed from here but are still in script>
}

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.print = function(Sender,...) -- ... represents the arguments that are sent
	local Message = table.concat({...}," ")
	print("From " ..Sender.Name..":\n"..Message)
end

Commands.addrankpoints = function(Sender, PlayerGiven, Cash)
	game.Players[PlayerGiven].leaderstats.RankPoints.Value = game.Players[PlayerGiven].leaderstats.RankPoints.Value + Cash
end

Commands.addrp = function(Sender, PlayerGiven, Cash)
	game.Players[PlayerGiven].leaderstats.RankPoints.Value = game.Players[PlayerGiven].leaderstats.RankPoints.Value + Cash
end

Commands.delrp = function(Sender, PlayerGiven, Cash)
	game.Players[PlayerGiven].leaderstats.RankPoints.Value = game.Players[PlayerGiven].leaderstats.RankPoints.Value - Cash
end

Commands.removerankpoints = function(Sender, PlayerGiven, Cash)
	game.Players[PlayerGiven].leaderstats.RankPoints.Value = game.Players[PlayerGiven].leaderstats.RankPoints.Value - Cash
end

Commands.setrankpoints = function(Sender, PlayerGiven, Cash)
	game.Players[PlayerGiven].leaderstats.RankPoints.Value = Cash
end

Commands.setrp = function(Sender, PlayerGiven, Cash)
	game.Players[PlayerGiven].leaderstats.RankPoints.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, unpack(Arguments))
		end
	end
end

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

3 comments

0

the line numbers arent the same what exactly is the code on line where youre getting error?

0

Could you post your WHOLE code so we can see exactly where the error occurs and help you identify the issue and how it can be solved?

0

killerbrenden my entire code is here, the only thing I have removed is my adminlist, which is just my admin's userIDs.

1 answer

well i don't want to through your code(not intending to be rude), but here is my suggestion, think of a command as function, the command can have arguments just like function.(exactly how command line arguments on your computer work)

so like this-> :add <arguemnts>

for example: :add coins 200. here add is the command, coins is an arguments, and 200 is also an argument, the colons(:) is an indicator that this is meant to be a command, and the spaces indicate a new argument

now once you parse the command and all it's arguments, then you can pass it's arguments to an appropriate command processor:

for example:

local Players = game.Players
local processors = {}
function processors.add_points(delta, player)
	
end

local admins = {"void_node","builderman"};

Players.PlayerAdded:Connect(function(player)
	for _, admin in pairs(admins) do
		if(player.Name:lower() == admin:lower())
			player.Chatted:Connect(OnChatted)
			break
		end
	end
end

local MSG_PREFIX = ":"
function OnChatted(message)

end

i have to go for now, but i will finish answer the question tomorrow

4 comments

0

that is what she is doing in her code

0

I wouldnt use UserNames as players can fake it but they cant fake UserId

0

with filtering enabled, they can't

0

I already have that, its refusing to parse its message though. Here is what I mean: I do :addrp [number]. it says its expecting a string instead of an object.

This discussion is preserved as it was. New answers, comments, and votes are closed.