Ban system not "trusting" anyone

I’m trying to make a system where if a player’s UserId is part of a list of banned user IDs, the banned player gets kicked from the game. But instead, all it does is auto-kick the player regardless.

game.Players.PlayerAdded:Connect(function(player)
	local playerCount = #game.Players:GetPlayers()
	print(playerCount .. " players")
	
	local bannedUsers = {}
	local playerUserId = "Player"..player.UserId
	local playerChosen = 0
	for playerCount, Player in pairs(game.Players:GetPlayers()) do	
		wait(0.1)
		playerChosen += 1
		if playerUserId then playerUserId = bannedUsers[playerChosen] do
				player:Kick("You are banned from this game")
			end
		end
	end
end)
2 Likes

Why are you getting all players? You just need to do this:

local bannedUsers = {1234567, 3456789}
game.Players.PlayerAdded:Connect(function(player)
	if table.find(bannedUsers, player.UserId) then
		player:Kick("You are banned from this game")
		return
	end
end)

Let me know if I misunderstood what you want to do.

1 Like

I misunderstood because I thought I wanted to get an item from a list. Like, variable = 1, then we get item 1 of the list.

Edit: Just found out I had to replace it entirely. It works now; thanks for your help!

Here’s an anti-autoclicker system I made before the ban script you helped me with (everything above the mouse connect is the base click script):

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local clickEvent = game.ReplicatedStorage:WaitForChild('ClickEvent')
local clicksPerSecond = 0

local function onMouseClick()
	clickEvent:FireServer(player)
	print("click fired")
	clicksPerSecond += 1
end

mouse.Button1Down:Connect(onMouseClick)

while true do
	wait(1)
	print(clicksPerSecond .. " clicks per second")
	if clicksPerSecond > 20 then
		player:Kick("The server has automatically kicked you for using an auto-clicker. Auto-clickers are not allowed on Roblox!")
	end
	clicksPerSecond = 0
end
1 Like
local bannedUsers = {1234567, 3456789} --id of banned players
game.Players.PlayerAdded:Connect(function(player)
	if table.find(bannedUsers, player.UserId) then --when a player joined and his id was found in the list
		player:Kick("You are banned from this game") --kick player
		return
	end
end)

What exactly do you not understand?

1 Like

I already understand it now, but thanks for trying to help

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.