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.
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
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.