A Custom Ban Script

Hello, I’m a beginner Lua scripter and I’m wondering why my script won’t work. I would like to make a script that bans somebody permanently and the only way to remove the ban is by removing the username on the script. Even with Adonis, I want it where the person is banned on the script, even if they are unbanned. Hopefully that makes sense. By the way, I have it in ServerScriptStorage.

Here’s the script:

game.Players.PlayersAdded:Connect(function(player)
	if player.Named == {"Fuserna"} or {"FNTDREAMSreborn"} then
	player:Kick("Sorry")
	end
	end)

This is just for testing, and I would like if somebody can revamp it so it can work!

2 Likes
game.Players.PlayersAdded:Connect(function(player)
	if player.Name == "Fuserna" or player.Name = "FNTDREAMSreborn" then
		player:Kick("Sorry")
	end
end)

By the way, using UserIds is better in case the player changes their username. You could do something like this instead:

game.Players.PlayersAdded:Connect(function(player)
	if player.UserId == ThePlayersUserId or player.UserId == TheOtherPlayersUserId then
		player:Kick("Sorry")
	end
end)

This is a more organized way to do it:

local BannedPlayers = {
--Put their userids in a table
}

game.Players.PlayerAdded:Connect(function(player)
	if table.find(player.UserId, BannedPlayers) then
		player:Kick("Sorry")
	end
end)
1 Like
game.Players.PlayersAdded:Connect(function(player)
	if player.Name == "Fuserna" or player.Name == "FNTDREAMSreborn" then
	player:Kick("Sorry")
	end
end)
2 Likes

That would ban all players as all players would fall under the “FNTDREAMSreborn” condition. Strings always return true.

2 Likes

Here

game.Players.PlayersAdded:Connect(function(player)
	if player.Name == "Fuserna" or "FNTDREAMSreborn" then
	player:Kick("Sorry")
	end
	end)

If you don’t mind me asking, where did you get “Named” and {“”} in the original script?

1 Like

You are right, I forgot to do that.

You have done the exact same mistake.

It should be this instead:

game.Players.PlayersAdded:Connect(function(player)
	if player.Name == "Fuserna" or player.Name == "FNTDREAMSreborn" then
	player:Kick("Sorry")
	end
	end)

I seen the {"} thing in some scripts that work.

Like if you said "/sg Gun} - It’s basically like a specific word(s) to spawn a gun (with limited spawns of course) - (with your name added on the script, it wouldve work), idk I just saw that in some script.

And I don’t know about the “Named” thing, I think I probably misspelled it or did something wrong with it.

I just realized that.

I didn’t proof read his thing, I just copied it and thought it would work. I knew how to code it but reading his post made my brain miss it.

Would this work?


--game.Players.PlayersAdded:Connect(function(player)
--	if player.Name == "Fuserna" or player.Name == "FNTDREAMSreborn" then
--		player:Kick("Sorry")
	--end
--end)
local BannedPlayers = {
	"675726563"	--Put their userids in a table
}

game.Players.PlayersAdded:Connect(function(player)
	if table.find(player.UserId, BannedPlayers) then
		player:Kick("Sorry")
	end
end)

Do I put the quotes or nah?

Don’t add the quotes. Also, if you want to add more ids, add a colon or semicolon to the end of it.

somewhat unrelated script example
local BannedPlayers = {
	675726563;
	userid2;
	userid3;
}
local BannedPlayers = {
	675726563	--Put their userids in a table
}

game.Players.PlayersAdded:Connect(function(player)
	if table.find(BannedPlayers, player.UserId) then
		player:Kick("Sorry")
	end
end)

Doesn’t work.

I have the script in ServerScriptStorage. Do I need to change anything?

Are there any errors? Also, it must be a server script. I would put it in ServerScriptStorage but you technically could put it in workspace.

There are no red lines at all, it’s just not working. And yeah, I have it in SSS (ServerScriptStorage).

Make sure it is game.Players.PlayerAdded and not game.Players.PlayersAdded. I noticed that while I was testing it in my own game. It worked after I changed that.

the script without the error
local BannedPlayers = {
	675726563
}

game.Players.PlayerAdded:Connect(function(player)
	if table.find(BannedPlayers, player.UserId) then
		player:Kick("Sorry")
	end
end)
1 Like

IT WORKS YOO TYSM!!!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.