Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How would I make a ban list for this ban script I have made?

Asked by
0RKH 35
5 years ago

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.

3 answers

Log in to vote
0
Answered by
piRadians 297 Moderation Voter
5 years ago
Edited 5 years ago

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
0
If that’s the best method than thanks. 0RKH 35 — 5y
0
There's always multiple methods - but for something as simple as this, it's probably the best method. SummerEquinox 643 — 5y
Ad
Log in to vote
1
Answered by
green271 635 Moderation Voter
5 years ago

Tables and Modules

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 UserIds 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

Solution

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)
0
^ woah...I never thought of people changing their name, thank you. 0RKH 35 — 5y
Log in to vote
-2
Answered by
markjac -11
5 years ago
Edited 5 years ago

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.

0
Everyone is saying I should use a table, thanks too ^ 0RKH 35 — 5y
0
You're comparing a player's name (a string) to a table, and not the contents within the table. :/ TheeDeathCaster 2368 — 5y

Answer this question