BanManager | A light-weight ban handler!

Ban Manager

Description

Ban players utilizing this lightweight, easy to use module.

Documentation

.Ban

Bans the UserId with the specified kick message. If no message is provided, the default is "You have been banned." If the player is ingame, they will be kicked. When they rejoin, and their unban date has not been reached, they will also be kicked.

Ban length is how long the ban will last in seconds. If not specified, the player will not be unbanned until BanManager.Unban is used.

Extra data is any extra data you would like to add to the ban, for example, a moderator’s id, which you can see via BanManager.GetBanData(UserId).

You can always edit a ban by calling .Ban with your modified arguments.

Example:

BanManager.Ban(userId: number, message: string?, banLength: number?, extraData: table?)



.Unban

‎ Unbans the UserId.
BanManager.Unban(userId: number)

.GetBanData

‎ Returns the ban data of a UserId.
BanManager.GetBanData(userId: number)

For example, it could return this:

{
	IsBanned = true,
		BanMessage = "You have been banned for hacking",
		ExtraData = {ModeratorId = 111111},
		UnbanDate = 1670702500
}



.GetBanDatas

Returns ban datas based on a provided limit. If not inputted, it will return every ban data. There is an optional callback parameter that will be called while data is loading.

BanManager.GetBanDatas(limit: number?, callback: (userId: number, banData: {}) -> ()?)

Example code:

local allBanDatas = BanManager.GetBanDatas()
local firstTenBanDatas = BanManager.GetBanDatas(10)

-- You can use callbacks to do something while data is loading
local printTheseBanDatas = BanManager.GetBanDatas(100, function(userId, banData)
	print(`UserId: {userId}`)
	print(`BanData: {banData}`)
end)

-- Alternative version
BanManager.GetBanDatas(nil, function(userId, banData)
	print(`UserId: {userId}`)
	print(`BanData: {banData}`)
end)

For example, it could return this:

{
	[123456789] = {
		IsBanned = true,
		BanMessage = "You have been banned for hacking",
		ExtraData = {ModeratorId = 111111},
		UnbanDate = 1670702500
	},

	[987654321] = {
		IsBanned = true,
		BanMessage = "You have been banned for hacking",
		ExtraData = {ModeratorId = 111111},
		UnbanDate = 1670702500
	}
}



Setup

  1. First off, drag the module into ServerScriptService.
    ModuleLocation

  2. Enable Studio Access to API Services in game settings. You will need to publish your game to access this.

  3. Require the module in a server script and it will start up. Use any functions needed.

    Example code:

    -- Services
    local ServerScriptService = game:GetService("ServerScriptService")
    
    -- Modules
    local BanManager = require(ServerScriptService.BanManager)
    
    -- Functions
    task.wait(5)
    
    BanManager.Ban(
    	1, -- UserId
    	"u got banned", -- Ban message 
    	10, -- Ban length in seconds
    	{ModeratorNote = "this guy has a cool id"} -- Optional extra data
    )
    

Notable acknowledgements

  • Global bans are apart of this module. Players who are banned, ingame, but not in the same server, are promptly kicked using MessagingService

  • You can use this in any of your games without crediting me, so have fun banning people!

  • This is my first module, so feel free to leave feedback and feature ideas.

33 Likes

If messaging service fails to kick the player, does the datastore still get saved?

1 Like

Yes, data is saved before the server attempts to kick the player.

2 Likes

Great, by the way, to make it more useful you should add another parameter that specifies the time when the player will be unbanned, so, if the player joins and the currentTime is bigger or equal than the unban time then unban him

For example

local currentTime = DateTime.now()
local whenToUnban = currentTime.UnixTimestamp + 10000 --Random number i put lol

Ban(plr.UserId, "You will be unbanned in"..formatDate(whenToUnban), whenToUnban)
1 Like

I’ll try adding this in later.

1 Like

Minor Update

- Added a new Ban Length parameter. Specifies how long the ban will last for in seconds. Read the documentation for more info.


(Credits to @UltraYummyChocolate for the idea)

2 Likes

I see alot of potiential in this system, HOWEVER, the ModuleScript doesnt have an option to check if a player is banned (You have to make your own work around to do this)

So please do add a check, an example could be: BanManager:CheckIfPlayerIsBanned(player.UserId) or BanManager:Check(player.UserId)

Basically it would then check in the datastore if the player is banned or not and automatically kick the player. An example script of this could be:

game.Players.PlayerAdded:Connect(function(player)
      BanManager:CheckBan(player.UserId)
end)

If you implement this then I would definitely look forward to using this system.

1 Like

Yes, add a setting that we can set to true/false whether we want to kick banned players that join again or not

I already have some logic that kicks the player if they are banned. I could remove that logic so that you would have to do it yourself, but that’s only if quite a few people would like to do that.

1 Like

Yea but how is the BanManager gonna call it when there is no script to trigger it?

When any script uses:

require(ServerScriptService.BanManager)

It starts up, and does the necessary functions.

Even if a banned player joins after you require the module, it will still kick them due to the checks I added. This is why it would be useless to add a function to check if a player is banned.

You can test it on your own and see how it works. Make sure to require the module.

1 Like

Alright. Thanks for the clarification.

1 Like

Love this!
100% Bump.
You should keep this updated, not many ban systems are updated now of days.

1 Like

What features would you like?

Maybe a auto-format for timed-banned’s?

And as Hauber_RBLX said a method for checking bans would be nice.

BanManager:CheckBan(player.UserId)
returns true/false

1 Like

Update

  • Added a new IsBanned function. Returns true if the UserId is banned and false if they are not banned. More info on documentation

(Credits to @NotBugle for the idea)

2 Likes

:clap:
Thanks!!!
Im glade to see this update.

1 Like

While I do like the IsBanned function, I think it should return more info rather than just true or false.

Maybe have a function so in-game moderators / admins can ban players in-game?

BanManager.ModeratorBan(userId: number, moderator: number, message: string?, banLength: number?)

Which could result in something like this;

BanManager:IsBanned(userId: number) => [banned: boolean, moderator: userId?, reason: string?]
1 Like

Will we be able to return out a record of who is banned?