Community Tutorial Draft

:wave: Hello, and welcome to this advanced tutorial on how to create your own custom admin system for your roblox game. This tutorial will teach you how to construct an admin system that is very flexible and allows you to add your own custom commands with ease.

Before beginning this tutorial, you will need to make sure you have an understanding of the following topics:

Once you’ve completed this tutorial, any command you want to create can easily be added to your admin system. Each command added has a customizable list of arguments they are expecting the administrator to use in their chat message; when they use a command, the following text will be processed into the arguments that the command is actually expecting. This highly flexible system allows you to easily create and edit custom commands.


 1. Setup

This admin system will be comprised of three different parts:

  • Server Script for Chat Processing
  • Module Script for Commands Handling
  • Local Script for Client Gui Handling

These parts are arranged in the following configuration for the purpose of this tutorial:
Admin System Layout

(You can name your scripts whatever you want.)


 2. Admin Commands Handler Setup

The Admin Commands Handler Module Script will be where we are defining and organizing all commands in order for the Chat Handler to call upon. We will have a main function for adding commands called newCommand, we will call this function for every command want to add to the admin system. The newCommand function will consist of the following parameters:

Name Type Default Description
cmd string Identifier of the command that is being added. (eg. "kick" or "cmds")
level number Admin level required in order to run this command.
func function Function that is called when an admin runs this command.
desc string Description that explains the usage and effect of this command.
args table List of arguments processed from the chat msg passed to the command's function.

With those parameters in the newCommand function, your code should look like this:

function newCommand(cmd,lvl,func,desc,args)
	
end

Great, now we have our function for adding commands created, we will work on the actual algorithm for this function later. For now, we will be adding our first command so that it is easier to understand the newCommand function once we go to fully write it.

The first command we will be adding is the kick command, this command will be used to remove a specified player from the game when an admin runs the command. For our case, when an admin runs the kick command, we want to kick a player from the game with a reason provided by the admin that explains why they were kicked. In order to do this, the admin will need to provide the target player of the kick along with a string explaining why they were kicked. (Note: We must filter the kick reason before sending it to the kicked player in order to comply with Roblox Terms of Service)

In order to add the kick command, we need to decide each argument that we are going to send to the newCommand function when we call it. I have filled in every argument for calling the function as shown below, each labeled with a comment above to remind you what we are specifying with each argument.

--          cmd  lvl  func
newCommand("kick",1,function(chatplr,targetplr,str) 

--            desc                            args
end,"Removes a user from the game.",{"targetplr","string"})

As you can see, the last argument we send when calling newCommend is a table that represents exactly what arguments should be passed into the func above when the command is ran. For example, if an admin were to run :kick Vmena Exploiting, the chat processor would decide exactly what to send based on what the kick command is expecting. In this case, it would send Vmena as the first argument (targetplr) and Exploiting as the second argument (str). Please note, the chatplr (admin who ran the command) will always be the first parameter sent to the function.

All that has to be done to finish the kick command is to first filter the reason and then kick the player with that reason specified. The code for the complete command can be seen below:

-- chatplr is the player who ran the command
-- targetplr is the player who the admin wants to kick
-- str is a string of text representing the kick reason
newCommand("kick",1,function(chatplr,targetplr,str)
	local filteredstr
	pcall(function()
		filteredstr = Chat:FilterStringAsync(str,chatplr,targetplr)
	end)
	targetplr:Kick(filteredstr) -- kick with the specified reason (filtered)
end,"Removes a user from the game.",{"targetplr","string"})

Now that we understand how adding each command works, we need to completely finish up the newCommand function to properly handle the addition of new commands. First off, we’re going to need a table that stores information about each command that we add so that we can call these commands later when we want to run them. This table will be called Commands and will empty when we define it, adding more values for every time we call the newCommand function. Whenever we require the Admin Commands Handler module, the module will return this commands table to use when the Chat Processor wants to run a command. With all of this in mind, your entire code should look something like this:

-- Services
Chat = game:GetService("Chat")

-- Variables
Commands = {}

-- Abstraction
function newCommand(cmd,lvl,func,desc,args)
	
end

-- Commands Initialization
newCommand("kick",1,function(chatplr,targetplr,str)
	local filteredstr
	pcall(function()
		filteredstr = Chat:FilterStringAsync(str,chatplr,targetplr)
	end)
	targetplr:Kick(filteredstr)
end,"Removes a user from the game.",{"targetplr","string"})

-- Module Return
return Commands

Within the newCommand function, we will need another function that will be called by the Chat Processor whenever we want to run a command. The Chat Processor will send us two parameters, the chatplr (admin running the command) and args (the table of arguments that the command function will receive). We will need to then pass along those parameters properly into the command’s function when we call it.

function newCommand(cmd,lvl,func,desc,args)
	local function invokeCommand(chatplr,args)
		func(chatplr,unpack(args))
	end
end

Once we have our invokeCommand function ready, now we need to store the command into the Commands table. We will store this by using the cmd as the index and a table containing information about the command as the value. This table’s contents can be seen in the code below:

function newCommand(cmd,lvl,func,desc,args)
	local function invokeCommand(chatplr,args)
		func(chatplr,unpack(args))
	end
	Commands[cmd] = {
		["call"] = invokeCommand
		["desc"] = desc
		["args"] = desiredargs
	}
end

Great, now we have the newCommand function set up to where we can add any command with ease. We will get back to finalize the newCommand function later, before we do that we need to create the part of this script that decides who gets which level of admin.


 3. Admin Permissions

One of the most important parts of your admin system is making sure it is secure. Many of the free model admin systems that are out there can be exploited pretty easily to allow non-authorized users to run any admin commands on their own accord. Obviously, this is not what we want, so we will be doing all permissions handling and checks on the server to make sure nobody can act like they are an admin.

First off, we need to decide who will actually have admin permissions. For this system, we will have two ways of deciding this:

  • Specific users will receive admin
  • Specific ranks in a group will receive admin
2 Likes