So, i have been working on a Adminsystem lately and im trying to make a ranksystem, so lowerplayers (from grouprank) cant kick higher ups.
FindPlayer Function
local function findplayer(name)
for i, player in pairs(game.Players:GetPlayers())do
if (type(name) == "string") then
if string.match(player.Name:lower(), name:lower()) then
return player
end
else
if (player.Name == name.Name) then
return player
end
end
end
return nil
end
Rankcheck Function
local function rankcheck (playerfound, playerruncmd)
local value1 = playerruncmd:GetRankInGroup(5581334)
local value2 = playerfound:GetRankInGroup(5581334)
if value1 > value2 then
return true
end
return false
end
KickCmd
commands.kick = function(arguments, sender)
local playertobekicked = arguments
local playerruncmd = sender
if playertobekicked then
local playerfound = findplayer(playertobekicked)
if playerfound then
if rankcheck(playerruncmd, playerfound) then
playerfound:Kick("You have been kicked by an Admin! Reason: ")
end
end
end
end
Message Filter
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message, receipient)
if isAdmin(player) then
message = string.lower(message)
local splitstring = message:split(" ")
local commandtriger = splitstring[1]
local cmd = commandtriger:split(prefix)
local cmdname = cmd[2]
if commands[cmdname] then
local arguments = {}
for i = 2, #splitstring, 1 do
table.insert(arguments,splitstring[i])
end
commands[cmdname](player, arguments)
end
end
end)
end)
and whenever i run this command the following output comes: Screenshot by Lightshot
(this error points out the Rankcheck Function)
This might be because either playerfound or playerruncmd don’t exist; are you using valid parameters?
Does the find player function find the player effectively?
I see here that you mixed up the parameters. I think playerfound comes first judging by the rank check function.
Are you sure playertobekicked is the player? arguments would lead me to believe you are sending a table of arguments rather than a player or a player’s name.
well yes, but no. I was told it doesnt really make a difference and speaking from own experience without the “[1]” it works better than with, but i will try that real quick.
The “[1]” is referencing to the 1st item in the table. Without the “[1]” you are setting the variable to the whole table. It really depends what situation you are in and when it is appropriate to use it.
The issue has already been stated. In your Message Filter code, you are passing (player, arguments) into the commands[cmdname] function arguments. However, in the commands.kick code, you are taking the parameters (arguments, sender). The issue is that then sender should be player from the Message Filter code and the arguments should be changed.
The reason you got the error from arguments[1] is because you tried to check the first index of Player, which is an object and not a table. You either need to do commands[cmdname](arguments, player) or commands.kick = function(sender, arguments).
Also, you still need to do local playertobekicked = arguments[1] either way because arguments is a table and you need to get the first index of the table, which would be the player to be kicked. You’ll also need to do local playerruncmd = send.Name because you are passing the Player object into this function and not the .Name (string).
Alright, thanks for taking your time to write this. I will try that tomorrow and inform you if it worked or not and mark your reply as a solution if it works.