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?
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.
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)