I have been trying over and over for days to try and get this code to work but its just not work >:( I have tried everything from kicking the player if their name is the same as the subjects or even using gulp chatgpt gags.
and yet all it does is either kick just me even if my name is not the subjects name. Or it just prints out the “User not found” string, I can’t get my stupid code to work, All I want is a player to get kicked if their name is the same as “Subject” here’s my code.
Please help me, I’m losing my freaking mind.
Edit: Thank you all for the feedback its been helping a lot!
Edit but 2: Big thanks to “NOCOMPLYMOBY”, turns out all I had to do was add :lower() and it works like a charm! And thanks to everyone that gave me their thoughts on my code, I’m working on trying to improve it.
The first parameter given to a function connected to OnServerEvent is the player that fired the RemoteEvent. It is NOT a value that you give when firing the remote. So in your case, the function connected to the OnServerEvent will receive three values:
the player that fired the remote (Players.LocalPlayer in the local script)
the first value (Admin) given in the FireServer call
the second value (SubjectPlayer) given in the FireServer call
Since the function connected to OnServerEvent only has two parameters, the last value (SubjectPlayer) will not be used. The value of the parameter Admin is the player who fired the event and the value of the parameter Subject is the value that was called Admin in the LocalScript.
If Admin in the LocalScript is the LocalPlayer, just leave it out of the FireServer call. If not, then add a parameter to the connected function for the player who fired the event (this should be the first parameter).
I can’t think of a reason why the admin would not be the LocalPlayer, though. If it is the LocalPlayer, then the admin parameter of Commands["admin.kick"] is unnecessary as well.
Admin in Commands["admin.kick"] is apparently the same as Player in the code that handles the chat messages, so if this Player is always Players.LocalPlayer, then there’s no need to have the admin parameter in Commands["admin.kick"].
about the “User not found”, you might have entered the wrong name or you accidently pressed space 2 times. according to your code the Arguments is equal to message:split(" ") which may return: {"<the command>", "", "theplayername"}. also i dont recommend using GetDescendants to list players, since it will return all instances exist in Players. just use GetPlayers() and you are good to go.
This may be an extremely stupid answer but have you tried doing
if SubjectPlayer.Name == Subject.Name
it could possibly be the answer but i have no idea if it is the right answer because im pretty sure even chatgpt could figure it out if it was that easy.
No, this is the correct answer.
The server will always take .OnServerEvent:Connect(function(PlayerFired, param1, param2, ...)); however, in the OP’s post, the Local Script sends two arguments to the server :FireServer(Admin, SubjectPlayer), but the ServerScript also only has two parameters when it needs three. @Lion_Claac was correct.
do you see these lines? according to them the Admin is our player and the Subject is the player to kick, ban e.t.c. Our original poster just renamed player to Admin.
I understand you completely but the thing is he renamed player variable to Admin. you know renaming? changing of name? he did exactly that. He knows that Admin is our player.
He did not do that. If you look at line 19 in the first screenshot, the Local Script, he send (Admin, SubjectPlayer) and on line 6 of the second screenshot the server receives (Admin, Subject) which means that the Local Script sent TWO arguments and the server received TWO arguments NOT three. There is no renaming when there is not third parameter for the server to receive.
What are you trying to do even exactly? And why are you using remote events to kick?
also concat returns a string you might wanna use tostring(Player.UserId)
and if you’re trying to find players by partial string just use this
for _,v in game:GetService("Players"):GetPlayers() do
if v.Name:sub(1,#arg) == arg then
print(v.Name.." has similar phrase with arg")
end
end
I think you are over complicating the process, you can just add this script into ServerScriptService and thats it
-- !kick, dev_peashie, reason? cause yes... -- command
local admins = {1816810703} -- Admin IDs
local adminFuns = {
["!kick"] = function(plrKick, msg)
for _, p in pairs(game.Players:GetPlayers()) do
if string.lower(p.Name) == plrKick then
p:Kick(msg)
end
end
end,
}
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if table.find(admins, plr.UserId) then
if string.sub(msg, 1, 1) == "!" then
local theWarn = string.split(msg, ",")
local split = string.split(string.gsub(string.lower(msg), "%s", ""), ",")
adminFuns[split[1]](split[2],theWarn[3])
end
end
end)
end)
Its not optimized, I just typed it in a rush, but, it works.
Many replies in this topic could “kinda make it work”, but anyone, honestly, think that the OP’s approach is the right one?.. From Client firing a Remote to send the data, validate it and kick the player?.. when its just a matter of connect the Chatted event from ServerSide on join, handle the check if its admin, call the function and thats it?
Are we trying to just fix the wrong approach? or can we just suggest a better one? as I tried in my reply…