How to make a basic banning system

Help developers!

I am Dan_foodz, I have been making things on Roblox for a year or two.

I will be telling you how to make a basic banning system.

Basic Script useing Player Names:

First think we do is make a server script, name it what you want.

Next thing we do is make a list in the script of banned players:

Line 1: local BannedPlayers = {} -- List of banned players

Next we need to put players into the table:

Line 1: local BannedPlayers = {'PlayerNameHere', 'MorePlayers', 'JustMorePlayers'}
(List can go forever)

Next we need to know when the player joins so we use Players.PlayerAdded:

Line 1: game.Players.PlayerAdded:Connect(function(Player)
Line 2: -- Blank
Line 3: end)

Next we need to check the banned players and see if one of them is the player that joined using a for loop inside of Players.Added:

Line 2: for TimesLooped, BannedPlayerName in pairs(BannedPlayers) do
Line 3: if BannedPlayerName == Player.Name then
Line 4: -- Blank
Line 5: end
Line 6: end

Now in the if statement, we now know the player is on the BanedPlayers List. So we will kick the player.

Line 4: Player:kick('You are banned from this game.')
(You can make your own kick message by replacing the text between the two ')

And that’s is, if your BannedPlayer from your BanedPlayers List joins, it will say:
image

Full Script:

local BannedPlayers = {'PlayerNameHere', 'MorePlayers', 'JustMorePlayers'}

game.Players.PlayerAdded:Connect(function(Player)
    for TimesLooped, BannedPlayerName in pairs(BannedPlayers) do
    	if BannedPlayerName == Player.Name then
    		Player:kick('You are banned from this game.')
    	end
    end
end)

Basic Script useing Player UserIds:

First think we do is make a server script, name it what you want.

Next thing we do is make a list in the script of banned players:

Line 1: local BannedPlayers = {} -- List of banned players

Next we need to put players into the table:

Line 1: local BannedPlayers = {12345, 54321, 1232123}
(List can go forever)

Next we need to know when the player joins so we use Players.PlayerAdded:

Line 1: game.Players.PlayerAdded:Connect(function(Player)
Line 2: -- Blank
Line 3: end)

Next we need to check the banned players and see if one of them is the player that joined using a for loop inside of Players.Added:

Line 2: for TimesLooped, BannedPlayerUserId in pairs(BannedPlayers) do
Line 3: if BannedPlayerUserId == Player.UserId then
Line 4: -- Blank
Line 5: end
Line 6: end

Now in the if statement, we now know the player is on the BanedPlayers List. So we will kick the player.

Line 4: Player:kick('You are banned from this game.')
(You can make your own kick message by replacing the text between the two ')

And that’s is, if your BannedPlayer from your BanedPlayers List joins, it will say:
image

Full Script:

local BannedPlayers = {12345, 54321, 1232123}

game.Players.PlayerAdded:Connect(function(Player)
	for TimesLooped, BannedPlayerUserId in pairs(BannedPlayers) do
		if BannedPlayerUserId == Player.UserId then
			Player:kick('You are banned from this game.')
		end
	end
end)

Thats all it takes to make a banning system. There is many upgrades you can do to this script, but I will let you do that :slight_smile:

8 Likes

I don’t like how your tutorial is in this form. Please format it properly.

This is bad, as players could just change their name into something else. Use UserIds instead.

I recommend use index pairs (ipairs) for this.

Overall, this tutorial is okay. Just need some more improvements.

3 Likes

Did you read this?

This is just the basics, if the player want to they can change it to userId.

1 Like

Why give them a basic banning script if parts of it aren’t exactly the best it can be? Getting a player user id isn’t a difficult task and it would probably just be better to include it in the script.

That IS what tutorials for basic systems are, to get the best possible outcome while staying basic. It’s a learning process to know what fits and what doesn’t, rather than leaving them on their own.

2 Likes

Fixed, you can now do either PlayerNames or UserIds:

1 Like

Is there a reason you couldn’t use table.find over a for loop? I also think this is too basic to be helpful.

2 Likes

There is no reason I couldn’t use table.find. Other then I forgot it was a thing. I think it can help new developers, this is not for developers that have done all of this.

1 Like

Still, my point stands out. I’m just giving you a suggestion.

1 Like