So, recently I was making a ban script to keep a certain few lucky players out of my game, the script worked fine when I used usernames in the table but I didn’t want usernames since someone could easily change their username. I decided to replace the usernames with Id’s so I can ban them.
the script below is a server script in the server script service, I tried to use other tutorials from the dev fourm but they didn’t help out.
The issue is from using if instead of elseif along with way to many end statements. But this isn’t really a good method to begin with because it lacks scalability and impacts code readability. You are much better off doing a table search and if it comes back true then kick the player.
local banned = {}
game.Players.PlayerAdded:Connect(function(player)
if table.find(banned,player.UserId) then
player:Kick("You have been banned!")
end
end
A more simpler way would be to use the table.find function, and check if the Player’s ID who joined has a same value as inside the table:
local BannedUsers = {899315016, 1608083588, 1485345548, 1692531457, 119494498, 13265291, 834629979}
game.Players.PlayerAdded:Connect(function(Player)
if table.find(BannedUsers, Player.UserId) then
Player:Kick("You have been banned")
end
end)
This would be way better than checking for every value inside the table with tons of unnecessary conditional checks
I personally wouldn’t spend the time adding id’s, i would work on making a datastore type ban system and all you do is put there ROBLOX username say like in a gui you make and then summit what you have to the datastore instead of going into studio every time and adding id’s.