Teach me how to make custom admin commands

Well first let’s break down what an admin command is.

Generally it’s a prefix (so we know it’s a command and not just a chat message). Often this prefix is a slash or a colon.

So first thing we do is hook up to chat. Then we check if the first #prefix chars = prefix so we know it’s a command and to continue processing.

Next we have command words. Basically the command type to execute. Usually this and all of the properties are space separated, so we need to split our string by spaces or whatever delimiter you chose.

So now we have the command in a form similar to this
[“tp”, “player1”, “player2”] (note I removed the prefix)
Built from the command
“/tp player1 player2”

So now we go part by part and look up what’s expected. So for example we know that the tp command wants a player and another player. So we can look up in our command list (in the form of a dictionary) what those arguments are supposed to be for this command. We can then turn those properties to their correct type like player and finally pass them into a function tied to the command name.

Then just write that function however you need.

This is of course just one way to go about it. Sometimes commands might be more complex or have multiple valid forms. You can come up with some data structure to represent that or make a command take a string and process command specific logic internally. You also need decoders for like the player properties so you can find the player correctly. Often this is searching for the first string that starts with what you had typed and optionally ensuring there isn’t more than one option.

2 Likes

thx for the example script! I’ll be able to apply this

1 Like

Is there any thing else I need to about when making admin commands?

1 Like

Is there anything else I need to know about when making admin commands?

1 Like

I’ll might be posting more questions about this as long as this post stay open for a few days

1 Like

A formal Roblox CLI (Command Line Interface) would utilize string patterns to break down the input. An initial pattern is applied to the input to simultaneously verify the presence of an instigator prefix and separate the command from its arguments. Commands are ideally implemented in individual ModuleScripts. In these scripts, you will specify the command name, its aliases, its prerequisites, an argument parser, and the command functionality. The CLI core will locate the command by its name or alias, verify prerequisites, then run its argument parser on the previously isolated input component. The parser will use additional string patterns to break down the isolated input, and will produce tangible values. These values are then passed to the command function, and the command is executed. It’s likely that multiple commands will require similar inputs, so it’ll be wise to create a repository of standard argument parsers which can be assigned to the command

A great example of this high-level implementation is Cmdr. I recommend taking inspiration from its design

2 Likes

It’s saying inside the commands that “assigning 2 values to 1 variables leaves some values unused”

1 Like

You’ve implemented something incorrectly. Variables can only hold one value. You’re likely writing:

local x = 1, 2

This would only store 1, losing 2

1 Like

Ok, I’ve asked the assistant two times for this solution they both didn’t show any errors

I can use either commas or []

3 Likes

I like this guide, teach me more about them!

wery cool explanation! Thanks for making it so understandable :D.

This is outdated. The Player.Chatted event is now a legacy event. Roblox has defaulted all new experiences to use the new chat system, which does not incorporate that event.

@Fiikus_Top

but still you get the idea of how to do admin commands. Right?

Sure, but the overall approach is crude

whats the better way to make admin commands then?

My mistake, I haven’t touched on it in a while

For a forum question there’s no reason to give anything more than that, if he wanted a flawless system he will work and create it in time.

Most features will just be more and more applications of string functions. There’s not much else to it.

You can probably search online for most questions as admin systems are quite popular

1 Like

Okay, thanks will do that !

Manipulating strings is something I have to learn anyway