Player won't be kicked from game

Hmm… I seem to have run into 2 problems I cannot solve myself in the past 5 minutes, lol. Okay, to the point: My problem is, I am firing a RemoteEvent to kick a player from the server, and the event fires to a serverscript, kicking the player.

Server script:

game:GetService("ReplicatedStorage"):WaitForChild("KickEvent").OnServerEvent:Connect(function(kick, reason)
	local plrExists = game.Players:FindFirstChild(kick)
	if plrExists then
		print("Player exists. Kicking...")
		plrExists:Kick(reason)
		print("Kicked user " ..plrExists.Name .." for reason " ..reason)
	end
end)

Script firing the event:

local event = game:GetService("ReplicatedStorage"):WaitForChild("KickEvent")
local rsnBox = script.Parent.Parent.Parent.reason.Front.Input
local usrBox = script.Parent.Parent.Parent.playerName.Front.Input

script.Parent.MouseButton1Click:Connect(function()
	local kick = usrBox.Text
	local reason = rsnBox.Text
	event:FireServer(kick, reason)
end)

I am not getting any errors, but the serverscript is not printing, either.

(I do not know how to program, lol)

That looks good, try putting a print under plrExists like print(plrExists) reply with what shows up in the output

I get nil when I add the print, for some reason.

Reminder:

OnServerEvent will have the Player as the first parameter, then you can put your variables afterwards

game:GetService("ReplicatedStorage"):WaitForChild("KickEvent").OnServerEvent:Connect(function(player, kick, reason)

1 Like

That was my problem, thanks for the reminder!

1 Like

There’s also the risk of sending a remote event, literally for kicking players.

I didn’t read the script entirely, but I know that remote event of a players name to kick is kind of a bad idea, if you plan on kicking exploiters.

Just checked, it’s just a test to see how kicking works. It’s fine, but an exploiter can abuse this to kick everybody else. Remember: you can’t trust the client.

Yes, I considered this. Is there a way to make it so this is not possible for exploiters? I am thinking maybe to create a script that only inserts the events if a moderator is in-game.

True, but he kicked the player on a server-script, and clients don’t have access to server-scripts?

Maybe, but they are capable of Firing the Event numerous times from the client side I believe & messing with everything else in from their view (Aka changing the Gui’s Text)

Well, if they are trying to ban other players, there is already an extra parameter that they need to ban them, and the hacker will not likely wont think about that parameter.

Then what can you do to stop them???