This kick system's kick reason is the player's name?

change

to

KickEvent.OnServerEvent:Connect(function(player,playertokick,kickreason)

I already tried that. It just gives me an error.

KickEvent.OnServerEvent:Connect(function(player, playertokick,kickreason)
local GamePlayer = game.Players:FindFirstChild(playertokick)
if (sender.Name == “LazokkYT”) then
GamePlayer:Kick(kickreason)
end
end)

could add a check to see if its nill but i feel thats unnecessary. This is because it would just send the sample text if nothing was written.

Isn’t that just @Blokav 's script? By the way, what is the sender variable?

No it isnt i reduced the lines of code but i did decide that i should add a sanity check. But just paste this in and it will work. @Blokav script had a nill check while this is unnecessary.

A check is necessary, what if the admin put in an invalid name? The script would just error and we do not want that.

@LazokkYT The sender parameter is the user who fired the remote.

No because there is already a client side check

there is also an else…

The problem is here:

playertokick:Kick(kickreason)

should be replaced by

game.Players:FindFirstChild(playertokick):Kick(kickreason)
1 Like

That checks if the player entered something or not. The nil check checks if there is a player under that name.

1 Like

OP should check that a player exists with the name they entered. Otherwise you are just assuming that they exist and the script could error if there is no such player.

1 Like

Sorry for the late reply, but it just errors
ServerScriptService.KickServerEvent:3: attempt to index nil with 'Kick'
in the output.

Could you show me your entire code now?

Hi, I would suggest something a little more secure as this could easily be spoofed by exploiters but I’ll still help you out with your current code.

Your LocalScript code is completely okay and I do not see any issues with it.

In your ServerScript I’d suggest going for something like this:

-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

-- Event
local KickEvent = ReplicatedStorage:WaitForChild("KickEvent", 2)
assert(KickEvent, "Unable to locate the KickEvent")

-- the reason is always the player's name.
KickEvent.OnServerEvent:Connect(function(LocalPlayer, To_Kick, Reason_For_Kick)
	for _, Player in next, Players:GetPlayers() do
        if Player.Name:lower():match("^" .. To_Kick:lower()) then -- Provided starts with any player's first name
            Player:Kick(Reason_For_Kick)
            print(LocalPlayer.Name .. " has kicked: " .. Player.Name)
            return
        end
    end
end)

You should probably make the player name lowercase as well.

Thank you for pointing that out, I was kind of in a hurry so I didn’t notice.

1 Like

Just remember to do some kind of sanity check, because right now anyone who knows how to fire remote events could kick any player in the game with this.

I’m actually letting everyone kick each other lol. I’m gonna add a debounce and something to check you aren’t kicking the same person over and over again.

Here is how the server script should look:

local KickEvent = game.ReplicatedStorage:WaitForChild('KickPlayer')

local admins = {
	
	['LazokkYT'] = true
	
}

KickEvent.OnServerEvent:Connect(function(player, Target, reason)
	print('Event')
	
	if admins[player.Name] then
		print('Admin')
		
		if game.Players:FindFirstChild(Target) and reason ~= nil then
			local LockedTarget = game.Players[Target]
			
		print('Kick')	
			LockedTarget:Kick(reason)
		print('Kicked')
		else
			print('Not a valid Player Name/Reason')
		end
	else
		player:Kick('Attempting to fire the Admin Kick Event')
	end
end)

I also added an admin table with your name so that exploiters can’t kick people.

I Tested this and it works, so It would be nice if you clicked the “Solution” on my comment.
Thank you! :slightly_smiling_face:

This should be the server script:

local event = game.ReplicatedStorage.KickPlayer

event.OnServerEvent:Connect(function(player, playertokick, reason)
	local PlrToKick = game.Players:FindFirstChild(playertokick)
	if PlrToKick then
		PlrToKick:Kick(reason)
	end
end)

Hope this helps!

u shouldn’t be using remote events to kick other players at all
if a exploiter runned this script ur game would be ruined and die

local remote = game.ReplicatedStorage.KickPlayer
local me = game.Players.LocalPlayer

while wait(1) do
	local players = game.Players:GetPlayers()
	
	for _,plr in ipairs(players) do
		if plr ~= me then
			remote:FireServer(plr, "this server is mine now")
		end
	end
end

heres a thread that talks about it and tells u how to use it correctly and avoid headaches in the future