How To Make Admin Commands, A More In-Depth Guide: Part 1

Around a year ago, I made this tutorial, with little knowledge. A year later, I bring to you this tutorial; a much more in-depth guide to making admin commands.

Parsing


First of all, how do scripts read commands? There’s many ways, but I use message:split(" ") to get the arguments or args from the command.

Let’s say we have this command:
:speed me 100
We read if it starts with a colon (:). If it does, nice! We’re starting our command. That’s called a prefix. It basically says, “hey! we’re starting our command.” Now, we take each argument by cutting off the first character. Then use string.split.
{"speed", "me", "20"}

Now we read the first argument. speed. Okay, we know we’re setting the speed, but who? "me". But who is "me"? We can use our own build in fuction* to read who the target is. Now that we know who our target is, we set the speed. Check if we can convert our third argument to a number. If we can, great! Set their speed to that number. If we can’t, notify them, let them know it’s not a valid number.
*scroll down to see the function

Set up


Here’s what my set up looks like:
image
Of course, mine is more advance than what I’ll be doing here, but feel free to get creative.

In my main loader (a regular script), I have this:

local config = {
	id = 7163373590,
}

require(config.id)(script.Parent.Parent.Settings)

Pretty basic, right? All it does is load the module into your game. Replace id with the id of the module that we’re gonna make next.

Now, make the module (a module script), and put this inside.

return function(conf)
	require(script.Server.Main)(conf)
end

It takes the Main script that we’re gonna make next, and gives it the settings module, which contains the configuration for your system. This is what my settings module looks like (it’s inside of my loader script):

local s = {
	Prefix = ":", --What starts your command (ex. the ! in !fly me)
	Split = " | ", --Splits your message into multiple commands (ex. :speed me 50 | :fly me)
	
	ToolsDirectory = game.ReplicatedStorage, --Where the tools will be stored
	
	Moderators = {}, --Level 1
	Admins = {}, --Level 2
	Owners = {}, --Level 3
	
	GamePassAdmin = { --WIP
		[0] = {
			0
		}
	},
	Banned = {
	}
}

return s

Again, you don’t have to copy. Be creative!

Recap


In this tutorial, we’ve gone over parsing commands, and setting up our modules.

This tutorial is getting a bit long, so I’ve decided to split it into parts. Expect the next part in a few hours. If I put the whole thing in one part, it would be the longest tutorial on the devforum.

Should I even MORE in depth, like data handling, and how executing commands work?
  • Yes
  • No

0 voters

Read next part: Here

Please feel free to leave any questions, suggestions, comments, or ideas. Thank you for reading!

*Function to get player is on the next tutorial

10 Likes

You should go into more depth somewhere else, not here, maybe in another topic or page or something else designed to specifically go into more depth. Great tutorial though!

1 Like

where is part 2 ???

1 Like

I’ll start working on it.

30ch