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
-
First off, drag the module into ServerScriptService.
-
Enable Studio Access to API Services in game settings. You will need to publish your game to access this.
-
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! I would like to know if you add this into one of your games, but that’s completely your choice
-
This is my first module, so feel free to leave feedback and feature ideas.
Used by Product: Exe