Is it possible to make a ban module?

Hey was wondering if that is possible, I did this for example;

Controller:

local banned = game.ServerScriptService.BannedPlayers

game.Players.PlayerAdded:connect(function(p)
    if banned[p.Name] then
        p:Kick("You are banned from this game")
    end
end)

Module:

local BannedPlayers = {
["Example"] = true,
["Example"] = true,
["Example"] = true,
["Example"] = true,
	}

return BannedPlayers
 --example for banned players ["USERNAME"] = true,

Is this possible, and if so, did I do it correct?

Making a ban module/script is possible, it has been possible for a very long time.
However, if you’re banning a user from the game. You should use their UserIds, not names. As they can easily change their name and regain access to your game. Which is not at all ideal for a ban system.

Also going to point out in the controller section. If you don’t call require on the module it won’t work, and on the PlayerAdded event, you should be using :Connect not :connect, given the fact the latter is deprecated and should not be used anymore.

7 Likes

Alright, will use UserID’s but how can this be achieved, obtaining them from a module?

1 Like

If you want to save banned state, you can write to a data store.

1 Like

Obtaining a UserId from a module is as easy as what you’re doing to obtain the names from the module. You need to replace the string(s) in the dictionary with the Player’s UserId.
Then make the appropriate adjustments in the PlayerAdded event.


As stated by Quenty and Nuclear_Energy it is better to use a Datastore then it is to use a dictionary to log banned players. This way you can create a ban command, and that way it updates across all servers. Without needing to shut-down all instances just to ban someone.

2 Likes