PunishService - Warn, Kick, TempBan and Ban players easily!

Introduction

Hello I’m dand! You might of seen me on the dev forum before but if you don’t know I’m a 2 year lua programmer who specialises in Backend and some Gui’s.

PunishService I made in my free time just to make it easier to discipline players and log their history.

What is PunishService?

Punish service is just a module that has methods like :Ban :TempBan :Kick :Warn and logs these in a datastore.

Most of it is just easy datastore saving and loading whether a player is banned or not but I’ve tried to make it the most efficient wayI could think of which also having functionality. This includes the use of JSONEncode and JSONDecode to easily save tables to the datastore.

It also comes with a Config module with settings that are easily changeable and accessable.


Setup

Setting up the module is pretty easy, just require the module and Invoke the Setup method and then you can use the module.

MAKE SURE TO ONLY CALL SETUP IN ONE SCRIPT AND NOT MULTIPLE

local PunishService = require(game.ServerStorage.Modules.PunishService)
PunishService:Setup()

-- later on
PunishService:Kick(player.UserId, 'hacking')

Configuration

Inside the module is a module named Config that contains the settings for PunishService

Blacklist and Whitelist information can be found below.

KickMessage - The message that appears at the bottom of the kick message. Can be used to encourage appeals or to poke fun at the player.

image

WarnKick - How many warnings until you are kicked.
WarnTempBan - How many warnings until you are temporarily banned for a day.
WarnBan - How many warnings until you are banned.

Expect more configurations soon


API

Warn

Property Type Default Description
Reason string nil The reason associated with the warning.
Issue number tick() The time the warning was given.
Author string string The name of the issuer

Gives the player a warning and notifies the client

Image from Gyazo

You set the amount of warnings until a punishment in the Config script.
image

When a player reaches that amount of warnings it will be kicked/banned depending on the amount.

Warnings get logged.

Methods

Warn: Warns a player
GetWarn: Gets a warn with the given id
GetAllWarns: Returns an array of all the player’s warnings
ClearWarns: Removes all warnings from a player
RemoveWarn: Removes a warn with the id given

Returns: Warn Object

Example:

PunishStore:Warn(player.UserId, 'Spamming chat', 'Admin')

Kick

Just a simple kick. Very similar to player:Kick(), can only work when player is in game.

Methods

Kick: Kicks the given player.

Returns: nil

Example:

PunishService:Kick(player.UserId, 'Being annoying')

Ban

Property Type Default Description
Reason string nil The reason for the ban (displayed in kick message)
Issue number time The time the ban was issued.
Author string ‘N/A’ The name of the Issuer.
Length number 0 The length of the ban (Only used with TempBans)

Bans the player from the game

image

Bans get logged.

Methods

Ban: Bans the player forever until they are unbanned
TempBan: Bans the player for a given amount of time
Unban: Unbans the given player.
IsBanned: Returns a bool on whether the player is banned or not.

Returns: Ban Object

Example:

if Exploiting:IsBad() then
  PunishService:Ban(player.UserId, 'Exploiting', 'Admin')
else
  PunishService:TempBan(player.UserId, 86400, 'Exploiting', 'Admin')
end

Blacklists and Whitelists

A blacklist cannot be called by a function but is stored in a table in the Config module.

image

Blacklists can only be changed in studio and don’t require DataStores, so if you wanna permanently ban someone this would be a good place to store them.

Methods

IsBlacklisted: Returns a tuple: a bool and a string.
IsWhitelisted: Returns a boolean.

Other

Setup

Starts the module, ONLY CALL THIS ONCE

GetLog

Returns a dictionary on the given player’s ban and warnings.

Remove

Completely removes a player’s data from the datastore.
For security reasons.


Conclusion

Thanks for using PunishStore and feel free to give feedback below!

Dandcx

11 Likes

Very nice, but I would recommend using ternary instead of nested if statement, that would look better.
Example in your code:

function PunishService:IsWhitelisted(userid : number)
	return table.find(Config.Whitelist, userid) and true or false
end

And maybe string.format too if you would like:

player:Kick(string.format('\n\n-Temporarily Banned- (\' %s \'s)\n\nReason: %s\n\n %s', tostring(math.floor((ban.Issue+ban.Length)-tick())), tostring(ban.Reason or 'No reason given.'), Config.KickMessage))
3 Likes

Then again I could just use

function PunishService:IsWhitelisted(userid : number)
	return not not table.find(Config.Whitelist, userid)
end

Thanks for the feedback

2 Likes

This post was flagged by the community and is temporarily hidden.

It detects if the userid is inside the table, if it is it returns true, else it returns false

if table.find(Config.Whitelist, userid) then true else false
2 Likes

This post was flagged by the community and is temporarily hidden.

Is there an “Unban” feature? To Pardon those permanently banned if either they were banned by mistake or it is decided that they may be unbanned?

Yea its in the methods

Just do PunishService:Unban(userid)

2 Likes

Ah. My bad! I didn’t see that. Thanks for telling me!

Also, I have a question. How does the Warn system work exactly? I warned the player but the player got no indication that they were being warned. Am I doing something wrong?

As a test I was doing it where they step on a part and it warns them. So here is my code:

local DB = true

local PunishService = require(game.ServerScriptService.PunishService)

script.Parent.Touched:Connect(function(hit)
	
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if DB == false then

		DB = true

		PunishService:Warn(Player.UserId, "Testing", "Me")
		
		wait(2)
		
		DB = false
		
	end
	
end)

Thanks and sorry for the trouble!

You just need to setup the module

local PunishService = require(game.ServerScriptService.PunishService)
PunishService:Setup()

But make sure to only call Setup once

1 Like

It still doesn’t seem to be working. I am so sorry for the trouble.

Just add an if statement to make sure its a player that touched the part

script.Parent.Touched:Connect(function(hit)
	
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
	    if DB == false then

		    DB = true

		    PunishService:Warn(Player.UserId, "Testing", "Me")
		
		    wait(2)
		
		    DB = false
		
	   end
    end
end)
2 Likes

Hello. Sorry for the late response. Just tried it it still doesn’t appear to be working. I am so sorry for the trouble.

It’s ternary operator (not really a ternary one since the original ternary only check 1 condition), use to wrap some statements into 1 line. The formula would be:

local X = 1
print(X == 2 and "X is 2" or "X is 1")

X == 2 is the condition for X is 2. If it’s false, the condition after or will run
Here you can include many check if you would like:

print(condition1 and statement1 or condition2 and statement2 or conditionN and statementN)