Hello everyone, today I will be doing a tutorial on how to make a configurable admin system! This will allow you to create you own commands that can do whatever you want (You have to script it) and they also take in arguments from the command that you can use. Without any further to do, let’s get right into it!
Step 1: Create Script and Variables
First off, you will want to create a Script in Workspace and you can call it whatever you like. After that you have to create the variables which is fairly simple. Just change these variables to how you like.
local Admins = {231214541,12345678} -- Change this to all the Player Admins' User Ids
local prefix = "!" -- The Command Prefix you would like to use
Step 2: Functions
After creating the variables, you can now write the code to make this work. We must create functions to make it able for commands to work.
game.Players.PlayerAdded:Connect(function(Player)
-- Checks if player is an admin
if table.find(Admins,Player.UserId) then
print(Player.Name.." is an Admin!")
Player.Chatted:Connect(function(Message)
-- This is where the commands will happen
end)
end
end)
Step 3: Making Commands Work
Now that the functions are created, you can now make it so it gets the command’s arguments and things happen when commands are used! First, we have to check if the message starts with the prefix. Put this code inside the Player.Chatted
Function:
if string.sub(Message,1,string.len(prefix)) == prefix then
-- This is a command
end
Now that the script is able to detect if the message is a command or not, if the message is a command, then it has to check for the arguments, so now add this code into the if
statement:
local Arguments = string.split(Message," ")
local Command = string.lower(string.sub(Arguments[1],2,string.len(Arguments[1])))
table.remove(Arguments,1)
Now that we have the Command and it’s arguments, we can now create a command! This is an example of a very basic command (Add this code under the code you typed previously):
if Command == "print" then
print(Arguments[1])
end
Final Notes:
If you “Got Lost”, which could be very easy for some people, here is the whole code:
local Admins = {231214541,12345678} -- Change this to all the Player Admins' User Ids
local prefix = "!"
game.Players.PlayerAdded:Connect(function(Player)
-- Checks if player is an admin
if table.find(Admins,Player.UserId) then
print(Player.Name.." is an Admin!")
Player.Chatted:Connect(function(Message)
if string.sub(Message,1,1) == prefix then
-- Get Command/Arguments
local Arguments = string.split(Message," ")
local Command = string.sub(Arguments[1],2,string.len(Arguments[1]))
table.remove(Arguments,1)
-- Command Template
if Command == "print" then
print(Arguments[1])
end
end
end)
end
end)
Arguments
will be a table
with all arguments stated after the command.
E.g.: If the message was “!say Hi Hello”, Arguments[1]
would be “Hi” and Arguments[2]
would be “Hello”
Any other comments/questions? Just reply down below!
Also make sure to leave a reply down below to show me what amazing commands you were able to create!
Thanks for reading and I hope this tutorial will help you!