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