Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

2 comments

0

If that’s the best method than thanks.

0

There's always multiple methods - but for something as simple as this, it's probably the best method.

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

1 comment

0

^ woah...I never thought of people changing their name, thank you.


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.

2 comments

0

Everyone is saying I should use a table, thanks too ^

0

You're comparing a player's name (a string) to a table, and not the contents within the table. :/

This discussion is preserved as it was. New answers, comments, and votes are closed.