I'm losing my mind over this script [SOLVED!]

Admin is the player he just renamed it… (•_• )

1 Like

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.

1 Like

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.

Events.KickPlayer.OnServerEvent:Connect(function( player, Admin, Subject)
1 Like

I think you dont understand as well…
image
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.

1 Like

This is from the Roblox Wiki. Please read the blue text at the bottom.

2 Likes

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.

1 Like

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.

It needs to be (FiredUser, Admin, Subject)

3 Likes

Ohhh okay sorry my bad I didn’t see it (;‘-’ ). Sorry again.

all events fired from the client to the server have the first parameter being the player who fired the event

the client is firing the event passing in the parameters Admin and SubjectPlayer

BUT the server’s parameters are only Admin and Subject

since the first parameter of ANY event from the client to the server is the player who fired it. Admin is the player who fired it

and since the client passed in two arguments, now Subject is the player who ran the command because now its taking the arguments from the client

in short: change your on server event parameters to this
player, Admin, Subject

also, there is no need to loop through all of the players when you can just do
Players:FindFirstChild(Subject)

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)
image
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.

Just type in chat:
!kick, playerName, reason

2 Likes

Have you tried doing

if SubjectPlayer.Name:lower() == Subject thrn

I noticed you set the message to lower, figured that might have something do with it.

1 Like

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…

1 Like

Getting it to work should be first priority, then rewriting should be second.

2 Likes

Good, but I think totally the opposite… The code I suggested achieve the goal in less lines and not using Remotes.
Fixing a wrong approach doesnt makes sense to me when it can be done better… Are we really reading and understanding or just trying to fix?


I like debates, not trying to be rude or something

1 Like

remove the admin in line 19 so that it is Events.KickPlayer:FireServer(Subject)
The reason why it kicked you qas because the server end reveived it as (Player,Admin,Subject) the 2nd arg being the admin instead of the subject

I’d say @Dev_Peashie is right in saying that it’s better to suggest additional changes that fix other problems or otherwise make the code better instead of just fixing the problem the user asks for help with. Checking whether the player using the kick command is an admin should be done on the server (which Dev_Peashie’s code does) instead of doing it on the client. If the server doesn’t do this check, an exploiter that is not an admin can kick any other player they want to kick.

2 Likes

On the line right above :Kick() could you try "print(Subject.Name, Subject.Parent.Name)

Also is there any reason youre getting all the decsendants of the Players folder, instead of just the exact players?

I have now, thank you so much.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.