Simple Auto-Kick Script

(Sorry if this is bad this is my first tutorial)

Hello new developers! If exploiters have taken control of your game, you want to get rid of them, right? Here’s a simple auto-kick script for you, server-sided and protected from exploits!

  1. Add a script to Server Script Service.
  2. Type the following:
game.Players.PlayerAdded:Connect(function(player)
end)

Here’s how it works. Every time a player joins, the function fires. The first argument (in this case, player), is the player that joins.
3. In the function, type in this:

if player.Name == "INSERT_PLAYERNAME_HERE" then
end

so your script should be like this:

game.Players.PlayerAdded:Connect(function(player)
   if player.Name == "INSERT_PLAYERNAME_HERE" then
   end
end)

Now, the moment the player joins it checks the name of the player (player.Name). After that comes the last bit of code:
3. The actual kicking

game.Players.PlayerAdded:Connect(function(player)
   if player.Name == "INSERT_PLAYERNAME_HERE" then
      player:Kick("Kick message here")
   end
end)

using the :Kick function on the player that should be banned, it will automatically ban the player once the loading screen goes in.
To show you how it works, here’s a video of me kicking myself (Replacing the "INSERT_PLAYERNAME_HERE" part with my actual username):


And if you want to add another person, just add an or statement, like this:

if player.Name == "INSERT_PLAYERNAME_HERE1" or player.Name =-"INSERT_PLAYERNAME_HERE2" then

So that’s how to make a simple auto-kick script! Thanks for reading this!

3 Likes

Nice tutorial but could be improved.
First of all, NEVER use player names for kicking. Use user ID’s as the player can’t just change their name.
Secondly, it’s good practice to use game:GetService("Players") as opposed to game.Players.
Additionally, instead of using an extra if statement you could use a table, if you are kicking more than a couple of players.
Improved version:

PlayersToKick = {
[110389141] = "Kick message here", --a3nim
[2737759980] = "Kick message here", --NeoGaming_RBLX
}
game:GetService("Players").PlayerAdded:Connect(function(player)
   for user_id, kick_message in pairs(PlayersToKick) do
      if player.UserId == user_id then
         player:Kick(kick_message)
      end
   end
end)
19 Likes

I’d use tables, id’s & you could even add groups to kick. This tutorial should be revised & edited to ensure easy but reliable methods are used.

4 Likes

Great for your first tutorial! But there are things that can be improved upon:

  1. Use a table for the auto kick players. Like create a table, put the user ids in, and then in the if statement use table.find() with the table and the player id. This will make it much easier to add lots of players since you won’t have to use or every time.
  2. Use player ids, not names. The player can change their name at any time which would just stop the system from kicking them. If you want to use names, you can convert the names to ids in the script using Players | Roblox Creator Documentation.
2 Likes

Even a more improved version where lookup times in the average case are O(1) rather than O(n):

PlayersToKick = {
[110389141] = "Kick message here", --a3nim
[2737759980] = "Kick message here", --NeoGaming_RBLX
}
game:GetService("Players").PlayerAdded:Connect(function(player)
    if PlayersToKick[player.UserId] then 
        player:Kick(PlayersToKick[player.UserId])
    end
end)
4 Likes

Heres a version that supports groups and userids also sorry if my coding style is bad

local Players = {
	[1929053738] = "Kick message", -- UIPadding
	[1] = "Kick message" -- Roblox
}
local Groups = {
	[7] = "Kick message", -- Roblox Group
	[127081] = "Kick message" -- Roblox Wiki Group
}
game:GetService("Players").PlayerAdded:Connect(function(player)
	if Players[player.UserId] then
		player:Kick(Players[player.UserId])
	else
		for groupId, kickMessage in pairs(Groups) do
			if player:IsInGroup(groupId) then
				player:Kick(kickMessage)
			end
		end
	end
end)
4 Likes

It doesn’t work like this. You’d have to do

if player.Name == "player_name" or player.Name == "another_player_name" then

Yeah I found out when using that type of if condition for my game, I’ll fix that.