I’ve updated the code to be efficient, however I don’t have a tutorial made for it but here’s the updated code that I recommend you use.
local Admins = {-1,"Just2Terrify"}
local Prefix,Seperator = "/"," | "
local Commands = {
["Example Command"] = { --[["Title of the command"]]
CommandPhrases = {"example1","example2","ex1"}; --[[Add the phrases you want to use to trigger the event.. make sure it is lowercase.. else it won't see the phrase.]]
Level = 6, --[[This is the level of admin needed to use the command.]]
Active = true, --[[This determines if the command is able to be used or not.]]
Description = "This is where the commands description will be.", --[[This is where you describe what the command is supposed to do.]]
Function = function(Args) --[[This is the function that you need to call to run the command.]]
warn(Args)
end}
;
}
--[[This will put all string values into lowercase, credit to AskForHeaven for the idea.]]
for i, admin in Admins do
if typeof(admin) ~= "string" then
continue
end
Admins[i] = string.lower(admin)
end
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(message)
if not table.find(Admins,string.lower(plr.Name)) and not table.find(Admins,plr.UserId) then
return
end
warn(plr.Name.." has chatted.")
local checkForMultipleCmds = string.split(message," | ") or message
for Ind,SeparateCommand in pairs(checkForMultipleCmds) do
local searchForCommand = string.split(SeparateCommand, " ")[1] or SeparateCommand;local commandSent = string.split(searchForCommand,Prefix)[2]
if commandSent then
for Command,CommandTable in pairs(Commands) do
if not CommandTable.Active then
continue
end
if not table.find(CommandTable.CommandPhrases,string.lower(commandSent)) then
break
end
CommandTable.Function(string.split(SeparateCommand,commandSent.." ")[2])
end
end
end
end)
end)
Original Post
Beginning Note
This is made to help you understand how to create the basics of an Admin System, in the form of chat commands; I made sure to hide the coding portions, in-case you want to figure out how to code it on your own. I used the basics of coding for this, to make it much more understandable.
Essentials
I’m going to list a few things you need to understand before you start creating an admin system;
-
Understand how the server and client interact with each-other, and seperately. I can’t express how important this is, if I understood how the server and client co-existed… my first attempt at an admin system would of been drastically different. I’ve attached a link that explains this in some depth: click here.
-
Understand how RemoteEvents, & RemoteFunctions work. These are how you’ll communicate between the server and the client(s) for 99% of your commands. I’d also recommend learning what BindableEvents and BindableFunctions are. They can be handy in certain situations.
-
Your first try should be a learning experience for you. Your first admin system will not match the same level as some of the popular admin systems, such as Adonis and Kohls. Use it as a step towards a bigger goal.
-
Have fun with your creation. If you think something may be a little weird to add to an admin system, who cares? Give it a shot, the worst thing that can happen is you remove it later.
-
Take inspiration from others. They’re other admin systems that may have certain things you may want, don’t be afraid to use them as an inspiration to create your own system.
After you’ve gone through the essentials, you’re probably wondering how to start creating the admin system. All you need, is a script, and a RemoteEvent. Put the RemoteEvent in your ReplicatedStorage, and name it what you desire. Although I do recommend using a module script alongside a regular script… it isn’t necessary.
All of the steps
Step One
For this, I will be using a regular script only.
The first step, is to create a table that will hold your commands. Why do you need a table? This is so you can search through every command, to find which command you’re trying to activate. Here’s how I’d recommend structuring the table:
Scripting Example
local Commands = {
["Example Command"] = { --[["Title of the command"]]
CommandPhrases = {"example1","example2","ex1"}; --[[Add the phrases you want to use to trigger the event.]]
Level = 6, --[[This is the level of admin needed to use the command.]]
Active = true, --[[This determines if the command is able to be used or not.]]
Description = "This is where the commands description will be.", --[[This is where you describe what the command is supposed to do.]]
Function = function(plr) --[[This is the function that you need to call to run the command.]]
warn("Example Command in FunCommands Ran")
end}
;
}
Step Two
Create a connection to the player chatting. Here’s how you’d do that;
Scripting Example
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(message)
warn(message)
end)
end)
Step Three
Once you’ve been able to fire a message, you then need to create a way to find these commands; how you’d do that is by creating a In Pairs check;
Scripting Example
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(message)
for Command,CommandTable in pairs(Commands) do
warn(Command);warn(CommandTable)
end
end)
end)
Step Four
Once you know that it’s finding commands, and showing said commands in the output… you now set up an AdminTable. This is a very simple process, you can go off of UserName, or UserId. The consensus is to use the UserId as that can’t be changed, however; use what you are most comfortable with. Put this table at the very top of your script; this is how your entire code should look so far;
Scripting Example
local Admins = {"Just2Terrify"}
local Commands = {
["Example Command"] = { --[["Title of the command"]]
CommandPhrases = {"example1","example2","ex1"}; --[[Add the phrases you want to use to trigger the event.]]
Level = 6, --[[This is the level of admin needed to use the command.]]
Active = true, --[[This determines if the command is able to be used or not.]]
Description = "This is where the commands description will be.", --[[This is where you describe what the command is supposed to do.]]
Function = function(plr) --[[This is the function that you need to call to run the command.]]
warn("Example Command in FunCommands Ran")
end}
;
}
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(message)
for Command,CommandTable in pairs(Commands) do
warn(Command);warn(CommandTable)
end
end)
end)
Step Five
Create a check to make sure the player is an admin, here’s how you’d do that;
Scripting Example
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(message)
for Index,Value in pairs (Admins) do
if plr.UserId == Value or string.lower(plr.Name) == string.lower(Value) then
for Command,CommandTable in pairs(Commands) do
warn(Command);warn(CommandTable)
end
end
end
end)
end)
Step Six
Now, you’d want to check if the message sent is a command phrase. I went ahead and did the liberty of creating the check… I will explain how I did it below the code:
Scripting Example
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(message)
local messageSent = message;local checkForMultipleCmds = string.split(messageSent," | ") or messageSent
for Ind,SeparateCommand in pairs(checkForMultipleCmds) do
local searchForCommand = string.split(SeparateCommand, " ")[1] or SeparateCommand;local commandSent = string.split(searchForCommand,Prefix)[2]
if commandSent then
for Index,Value in pairs (Admins) do
if plr.UserId == Value or string.lower(plr.Name) == string.lower(Value) then
for Command,CommandTable in pairs(Commands) do
for TableName,Phrase in pairs(CommandTable.CommandPhrases) do
if string.lower(Phrase) == string.lower(commandSent) then
warn("COMMAND SENT!");warn(SeparateCommand)
end
end
end
end
end
end
end
end)
end)
NOTE
The final code was altered to send the original message through the function as the message was originally sent. This makes it where you can send messages to other people without everything being lowercase.
You’ll see that there’s a bunch of extra in pairs tables, and variables. I’ve removed cap-sensitivity to the commands by making them all lowercase in the Chatted function. I’ve also made it so you’re able to send multiple messages by putting a |
at the end of each command with a space on each side. (example: /ex1 yes | /ex1 no
)
Step Seven
If the message is sent by an admin, and is a recongized command, and is active; fire the function of the command. Here’s how you’d do that;
Scripting Example
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(message)
local checkForMultipleCmds = string.split(message," | ") or message
for Ind,SeparateCommand in pairs(checkForMultipleCmds) do
local searchForCommand = string.split(SeparateCommand, " ")[1] or SeparateCommand;local commandSent = string.split(searchForCommand,Prefix)[2]
if commandSent then
for Index,Value in pairs (Admins) do
if plr.UserId == Value or string.lower(plr.Name) == string.lower(Value) then
for Command,CommandTable in pairs(Commands) do
for TableName,Phrase in pairs(CommandTable.CommandPhrases) do
if CommandTable.Active and string.lower(Phrase) == string.lower(commandSent) then
CommandTable.Function(string.split(SeparateCommand,commandSent.." ")[2])
end
end
end
end
end
end
end
end)
end)
This will now send anything after the command and a space; to the function. Example:
Final Script
Here’s what the code should look like now;
local Admins = {"Just2Terrify"}
local Prefix = "/"
local Commands = {
["Example Command"] = { --[["Title of the command"]]
CommandPhrases = {"example1","example2","ex1"}; --[[Add the phrases you want to use to trigger the event.]]
Level = 6, --[[This is the level of admin needed to use the command.]]
Active = true, --[[This determines if the command is able to be used or not.]]
Description = "This is where the commands description will be.", --[[This is where you describe what the command is supposed to do.]]
Function = function(Args) --[[This is the function that you need to call to run the command.]]
warn(Args)
end}
;
}
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(message)
local checkForMultipleCmds = string.split(message," | ") or message
for Ind,SeparateCommand in pairs(checkForMultipleCmds) do
local searchForCommand = string.split(SeparateCommand, " ")[1] or SeparateCommand;local commandSent = string.split(searchForCommand,Prefix)[2]
if commandSent then
for Index,Value in pairs (Admins) do
if plr.UserId == Value or string.lower(plr.Name) == string.lower(Value) then
for Command,CommandTable in pairs(Commands) do
for TableName,Phrase in pairs(CommandTable.CommandPhrases) do
if CommandTable.Active and string.lower(Phrase) == string.lower(commandSent) then
CommandTable.Function(string.split(SeparateCommand,commandSent.." ")[2])
end
end
end
end
end
end
end
end)
end)
Now, you simply need to code the commands to do what you desire. I hope this helps you, and others in the future.
I made this with the intention of answering @ShermaanCat’s post How to code a good admin system?, then realized I spent four hours writing this; and put way too much detail into it. I figured it would be a better tutorial at the point it’s at. This is my first tutorial, so if you’d like more information on a certain section; let me know.
2024-07-12T04:00:00Z