Help for Blacklist

REPOST from incorrect usage

I had this idea of making a blacklist for a project I made myself, and I have no clue why it is not outputting the player:Kick() message.

Here it is:

local BlacklistedPlayers = {
	'osb21313' --REMEMBER TO USE ONLY THEIR USERNAMES, NOT A DISPLAY NAME, OR IT WILL NOT WORK!
}

for i, player in pairs(game.Players:GetChildren()) do
	if game.Players:FindFirstChild(player.Name) and table.find(BlacklistedPlayers, player.Name) then
		player:Kick('You have been blacklisted from this game.')
		warn(player..' has been kicked from this game.')
	else
		return
	end
end

From using info that I know, do you know how it isn’t working?

1 Like

This is better practice.

local BlacklistedPlayers = {
   1,
   2
}
game:GetService("Players").PlayerAdded:Connect(function(plr)
   if table.find(BlacklistedPlayers, plr.UserId) then
      plr:Kick()
   end
end)

The PlayerAdded fires when a new player has joined, and checks for their User ID (which doesn’t change) to see if it is in the table. Your script not only runs only once, but if the blacklisted player changes their username, they won’t be getting kicked anymore.

Thanks! :sweat_smile: Did you forget

local playerToKick = game.Players:GetPlayerNameFromUserIdAsync(plr.UserId)

and

if playerToKick and table.find(BlacklistedPlayers, playerToKick.UserId) then
      plr:Kick('Reason')
else
      return
end

?

I created one today!

local sucker = game.Players.LocalPlayer
if sucker.UserId == 00000 then --change 00000 to id you want
sucker:Kick("Reason")
end

As I said, usernames are not best for your use case. And the return part should do the same for my script.

people can change their usernames and they won’t be blacklisted anymore, and the game.Players:GetChildren() is equivalent to game.Players:GetPlayers() but I recommend using this script for better blacklisting

local Players = game:GetService("Players")

local blacklistedUsers = {
	532043350
}

Players.PlayerAdded:Connect(function(player)
	if table.find(blacklistedUsers, player.UserId) then
		player:Kick('You have been blacklisted from this game.')
		warn(`{player} has been kicked from this game.`)
	else
		return
	end
end)
1 Like

Bro, how did you even get my UserID?

you used your username as an example, so I went to your profile and grabbed the userid in the URL and put it there