How can I make a blacklisted players list where they cannot enter my game?

Hello, my name is Koala_Helper!
I want to achive a pban / blacklisted players list for my game.:

The issue is the script isn’t working. When I enter my user idit works, but other players usernames it doesn’t work.

I haven’t tried any solutions on the developer hub because nothing showed up to what I searched.


local banned = {} -- Player UserIDs go here in the format {UserID, UserID2, UserID3}
local Players = game:GetService("Players")

game.Players.PlayerAdded:Connect(function() 
	for _, v in pairs(game.Players:GetChildren()) do
		for i = 1, #banned do
			if v.UserId == banned[i] then
				v:Kick("You are blacklisted from this game!") -- You may set a custom message within the quotations
			end
		end
	end
end)
1 Like
local Blacklisted = {1,2,3} --UserIds (In this example, **ROBLOX, JOHN DOE, JANE DOE** won't be able to join the game)

game.Players.PlayerAdded:Connect(function(player)
 for x, y in pairs(Blacklisted) do
   if player.UserId == tonumber(y) then 
    --do whatever here
       player:Kick("Blacklisted")
   end
 end
end)

Thank you! I’ll try it now :slight_smile:

Alternativaly, you could use table.find, as nil evaluates to false, it won’t run if the user id found in the table

local blacklisted = { 1, 2, 3 };

game.Players.PlayerAdded:Connect(function(player)
   if table.find(blacklisted, player.UserId) then
      -- Blacklisted part
   end;
end);
1 Like

Try this instead

local blacklisted = {
   {
      UserId  = 0,
      Reason = "Blacklisted reason here"
   }
}

game.Players.PlayerAdded:Connect(function(player)
   for i,_ in pairs(blacklisted) do
      if table.find(blacklisted[i]["UserId"], player.UserId) then
         player:Kick("You are blacklisted from this game for the reason: "..blacklisted[i["Reason"]])
      end
   end
end)

I didnt test it out but hopefully it works!

6 Likes

A cross-server ban system

local DSS = game:GetService("DataStoreService")
local BanDS = DSS:GetDataStore("PermaBanDS")


game.Players.PlayerAdded:Connect(function(player)
	local Banned = BanDS:GetAsync(player.UserId) or {false}
	if Banned[1] then
		if Banned[2] ~= nil then
			player:Kick("You are banned from this server. Reason: "..Banned[2])
		else
			player:Kick("You are banned from this server.")
		end
	end
end)


function ModifyBan(player,value,reason)
	if typeof(player) == "Instance" then
		if player:IsA("Player") then
			if reason then
				if typeof(reason) == "string" or typeof(reason) == "number" then
					BanDS:SetAsync(player.UserId,{value,reason})
				else
					BanDS:SetAsync(player.UserId,{value})
				end
			else
				BanDS:SetAsync(player.UserId,{value})
			end
		end
	elseif typeof(player) == "number" then
		if reason then
			if typeof(reason) == "string" or typeof(reason) == "number" then
				BanDS:SetAsync(player,{value,reason})
			else
				BanDS:SetAsync(player,{value})
			end
		else
			BanDS:SetAsync(player,{value})
		end	
	end
end
---ModifyBan(100001,true,"Cheating")
---ModifyBan(100001,false)
---ModifyBan(game.Players["Player1"],true)
---ModifyBan(game.Players["Player1"],true,"Abuse")
---ModifyBan(game.Players["Player1"],false)
5 Likes