Hello there! I have made a event script in which will ban a certain player when they join.
game.Players.PlayerAdded:Connect(function() for i, v in pairs(game.Players:GetChildren()) do if v.Name == "Insert Player Name Here" then v:Kick("Hi you are banned") end end)
However, it would only ban 1 player.How would I be able to make this into a ban list which bans multiple people?
Any help will be greatly appreciated, thanks.
Make a table containing the players you don't want to be in your game.
local bans = {123213213,49494932} -- ids game.Players.PlayerAdded:Connect(function(plr) for i,v in pairs(bans) do if plr.UserId == v then plr:Kick("ha get rekt skrub") end end
To better store our information, we can use a table or module script containing a banned player's user id. For this example, we will use a table. A table can be used to store values, we will store our banned player's UserId
s in there.
Why their IDs? That way they will remain banned if they change their name.
To loop through the banned player list, we will use X,Y in pairs
. pairs
are commonly used to filter through a table of objects or values. In this situation, it will loop through a table of player's user ids.
Example of pairs
:
for i,v in pairs(game.Workspace:GetChildren()) do -- this will run and collect information about the workspace's children print(i) -- the first value (i) is the number of objects/values it collected. print(v.Name) -- the second value (v) is the actual object/value itself. This case, we will have to print the name. end
local BannedPlayers = { -- start of table 0, 1 } game.Players.PlayerAdded:Connect(function(plr) for _,banned in pairs(BannedPlayers) do if banned == plr.UserId then plr:Kick("Hi you are banned") end end end)
game.Players.PlayerAdded:Connect(function() for i, v in pairs(game.Players:GetChildren()) do if v.Name == {"name1","name2","name3","name4"} then v:Kick("Hi you are banned") end end)
you get the point.