Blacklisting Help

Trying to make a Blacklisting system, is there an easier way to do this? I’m really new to programming, thanks.

local BlacklistedPlayers1 = {
	1 --Builderman
}

local BanReason1 = "You have been banned indefinitely for the following reason: Exploiting"

--Exploit Ban Below
game.Players.PlayerAdded:Connect(function(player)
	for i, v in pairs(BlacklistedPlayers1) do
		if v == player.UserId then
			player:Ban(BanReason1)
		end
	end
end)

local BlacklistedPlayers2 = {
	2 --Example
}

local BanReason2 = "You have been banned indefinitely for the following reason: Hate Speech"

--Exploit Ban Below
game.Players.PlayerAdded:Connect(function(player)
	for i, v in pairs(BlacklistedPlayers2) do
		if v == player.UserId then
			player:Ban(BanReason2)
		end
	end
end)
2 Likes

You should use dataStoreService to store blacklisted players

1 Like

you can cache player’s blacklist reasons inside of keys of a table

local BlacklistedPlayers = {
     [UserId] = {
          BanReason = "Uh oh stinky cheerios"
     }
}

game.Players.PlayerAdded:Connect(function(player)
	local BlacklistedPlrTbl = BlacklistedPlayers[player.UserId]
        if BlacklistedPlrTbl then
              player:Kick(BlacklistedPlrTbl.BanReason)
        end
end)
2 Likes

it’s labeled, ‘unknown global’ even if I put the ID in.

You need to replace [UserId] with the userId of the blacklisted player

1 Like

Didn’t realize, thank you so much haha.

How would I be able to add multiple people for one major ban reason?

Well one way you can do this is by making it opposite of what you have the solution marked as so like this,


local BlacklistedPlayers = {
     ["Uh oh stinky cheerios"] = {
         UserId1,
         UserId2
     }
}

game.Players.PlayerAdded:Connect(function(player)
	for _, reason in ipairs(BlacklistedPlayers) do
       if reason[player.UserId] then
            player:Kick(reason)
       end
    end
end)

local BlacklistedPlayers = {
     ["Uh oh stinky cheerios"] = {
         [UserId1] = true,
         [UserId2] = true,
     }
}

game.Players.PlayerAdded:Connect(function(player)
	for KickReason, reason in pairs(BlacklistedPlayers) do
       if reason[player.UserId] then
            player:Kick(KickReason)
       end
    end
end)

his code was a teensy bit wrong, this should work

1 Like

Oops sorry about that I’m on mobile, it should be fixed now

Fixed:

1 Like

.
How would I make it for separate the reasons, so sorry.
.

local BlacklistedPlayers = {
	
	["You have been banned indefinitely for the following reason: EXPLOTING   						      			     					                						                            *THIS BAN IS NOT APPEABLE*"] = {
		1, --Builderman
		2 --Nullified0
		}
	["You have been banned indefinitely for the following reason: Hate Speech   						      			     					                						                            *THIS BAN IS NOT APPEABLE*"] = {
			3, --Random
			85387607 --Random
	}

	

game.Players.PlayerAdded:Connect(function(player)
	for _, reason in ipairs(BlacklistedPlayers) do
		if reason[player.UserId] then
			wait(1.5)
			player:Kick(reason)
		end
	end
end)

local BlacklistedPlayers = {
	
	["You have been banned indefinitely for the following reason: EXPLOTING   						      			     					                						                            *THIS BAN IS NOT APPEABLE*"] = {
		1, --Builderman
		2 --Nullified0
	},
	["You have been banned indefinitely for the following reason: Hate Speech   						      			     					                						                            *THIS BAN IS NOT APPEABLE*"] = {
		3, --Random
		85387607 --Random
	}
}
	

game.Players.PlayerAdded:Connect(function(player)
	for _, reason in ipairs(BlacklistedPlayers) do
		if reason[player.UserId] then
			wait(1.5)
			player:Kick(reason)
		end
	end
end)

This should still work! Make sure to mark the proper solution for people that need it in the future!

1 Like

No errors are shown but if I put my user ID in, it doesn’t kick me like it is supposed to for both prompts on ServerScriptService.

Alright we’ll this can be fixed with some simple debugging


local BlacklistedPlayers = {
	
	["You have been banned indefinitely for the following reason: EXPLOTING   						      			     					                						                            *THIS BAN IS NOT APPEABLE*"] = {
		1, --Builderman
		2 --Nullified0
	},
	["You have been banned indefinitely for the following reason: Hate Speech   						      			     					                						                            *THIS BAN IS NOT APPEABLE*"] = {
		3, --Random
		85387607 --Random
	}
}
	

game.Players.PlayerAdded:Connect(function(player)
	for reason, userIds in pairs(BlacklistedPlayers) do
      print(reason, userIds)
		if userIds[player.UserId] then
			wait(1.5)
			player:Kick(reason)
		end
	end
end)

Also I think I fixed it as well as adding prints

1 Like

It sadly still isnt working for both of them.

Ok well can you tell me what the output printed? This will help me out a lot to help you since I’m on mobile I can test it myself

 14:30:55.866  Requiring asset 512742721.
Callstack:
cloud_144938633.archimedesTwo.initiatePlugin.MainModule, line 29
cloud_144938633.archimedesTwo.initiatePlugin.MainModule, line 28
  -  Server
  14:30:55.967  Requiring asset 518094091.
Callstack:
cloud_144938633.archimedesTwo.initiatePlugin.MainModule, line 30
cloud_144938633.archimedesTwo.initiatePlugin.MainModule, line 28
  -  Server

Is that the full output?? Because then that would mean it’s not even looping

If that is the only output try another debugging script:

local BlacklistedPlayers = {
	
	["You have been banned indefinitely for the following reason: EXPLOTING   						      			     					                						                            *THIS BAN IS NOT APPEABLE*"] = {
		1, --Builderman
		2 --Nullified0
	},
	["You have been banned indefinitely for the following reason: Hate Speech   						      			     					                						                            *THIS BAN IS NOT APPEABLE*"] = {
		3, --Random
		85387607 --Random
	}
}
	

game.Players.PlayerAdded:Connect(function(player)
    print(BlacklistedPlayers)
	for reason, userIds in pairs(BlacklistedPlayers) do
      print(reason, userIds)
		if userIds[player.UserId] then
			wait(1.5)
			player:Kick(reason)
		end
	end
end)