Serverban script?

How would I go about creating a serverban script. I suppose it would be:

while wait() do
Player:Kick()
end

but that would most likely lag the moderator after doing a couple serverbans so whats the correct way to do it?

1 Like

What do you mean by serverban? Do you mean they are only banned from that one server?

1 Like

Yes, like they cannot join that one server until it shutsdown and a new one is made

1 Like

So I just tried to type a long complicated admin script but it would be too hard to explain.

I think basically what you need to do is add the ServerBanned guy to a table that saves only on the server. Then, if he joins, the script will check if his name is in the table and kick him.

2 Likes

Example Script regarding the concept above :stuck_out_tongue:


local playerBans = {}

game.Players.PlayerAdded:Connect(function(player)
   if table.find(playerBans, player.Name) then
      player:Kick()
   end
end)

-- Inserting a banned player into the table
table.insert(playerBans, player.Name)
3 Likes

I have a question, why did you insert the name of the player into the table again when you could’ve just add the ID inside the table earlier in the script?

1 Like

I believe in the OP (Original Post) they were asking about more of a command approach for being able to ban players from a server. A ban command.

So those are the base components for doing basic ban tables and stuff
Here an example of a more complete script.

local command = "!ban"
local playerBans = {}

game.Players.PlayerAdded:Connect(function(player)
   if table.find(playerBans, player.Name) then
      player:Kick()
   end
   if player:GetRankInGroup(1234567) > 20 then
      player.Chatted:Connect(function(message)
         if string.sub(message, 1, string.len(command)) == command then
            local arguments = string.split(message, " ")
            if game.Players:FindFirstChild(arguments[2]) then
                table.insert(playerBans, player.Name)
                game.Players:FindFirstChild(arguments[2]):Kick()
            end
         end
      end)
   end
end)

You can see where the concepts come into play

1 Like

Yeah what I did was I made all of that run off of a remote which then is fired through a button on an admin panel gui.

BanEvent.OnServerEvent:Connect(function(player, BanPlayer)
	
	local PlayerBan = game.Players:FindFirstChild(BanPlayer)
	if admins[player.Name] and PlayerBan then
		table.insert(playerBans, PlayerBan.Name)
		end

	
end)
2 Likes

Just a bit of a little side comment which may help you out

local function getPartialUsername(text)
	for i,v in ipairs(game.Players:GetPlayers()) do
		if string.find(string.lower(v.Name), string.lower(text)) then
			return v
		end
	end
	return false
end
BanEvent.OnServerEvent:Connect(function(player, BanPlayer)
	
	local PlayerBan = getPartialUsername(BanPlayer)
	if admins[player.Name] and PlayerBan then
		table.insert(playerBans, PlayerBan.Name)
	end

	
end)

You can use a function like this in order to find the player without having to put the full username in :stuck_out_tongue:

2 Likes