How would I make a script that would ban someone's ID from joining a game?

Title, preferably where I could ban multiple IDs.

Player | Documentation - Roblox Creator Hub Check this article out
Player | Documentation - Roblox Creator Hub and this one
Its easy to make a ban script so why not learn and do it yourself?
Simple script example:

local players = game:GetSerivce("Players")
local bannedIDS = {} --a table containing all the UserIDs you have banned
Players.OnPlayerAdded:Connect(function()
 local userID --get the player's UserID
 local question = table.find (bannedIDS, userID) -- check if the player's ID has been banned
 if question then
  Player:Kick --Kick the player if his ID has been banned
 end
end

Except change whitelist to blacklist and do if table.find(blacklist, player.UserId) then

I have this exact script.
I linked mine up to a module script so I can use it globally.

Let me go get it for you real quick

Base Script: (Does the kicking and banning)

local Bans = require() --Put a path or the ID of a module script

game.Players.PlayerAdded:Connect(function(player)
	if Bans[player.UserId] then
		player:Kick(Bans[player.UserId])
	end
end)

Bans:

	Bans = {
	[123456] = "Ban reason go brrr"
	
return Bans
-- we cant put all userid bans and username bans in one table since in 2016 usernames could be all numbers

local UserNameBans = {

CoolShank8 = 'yexploiter' -- value of the key is the reason he/she is banned

}

local UserIdBans = {

[298716168] = 'trolling'

}

-- if the player is banned by user and name the name bans takes precendance

game.Players.PlayerAdded:Connect(function(Player)

if UserNameBans[Player.Name] then

Player:Kick(UserNameBans[Player.Name])

elseif UserIdBans[Player.UserId] then

Player:Kick(UserIdBans[Player.UserId])

end

end)

I would use tables instead of arrays for a lot of bans

1 Like