How do command messages work?


So, as everyone as probably known and used before… there are things called Admin Commands.
What i’m talking about is the commands such as teleport/me/Mil or a custom command such as ring/all.

The Question

How would I make an “all” function.
How would I make an “first couple letters to match gets teleported.” (i.e; ring/mil… Notice my usernames first three letters.)
Do I need a Module script to hold all of the functions?

What I’ve Seen

I’ve looked at YouTube Tutorials but none of them have helped, i’ve looked up on the Dev Forum exactly what i’m looking for and I’m not finding anything that matches my certain description.

Thank you to anyone who takes the time to help me figure this out.

1 Like should help.


Admin systems typically make use of a string function called string.split, which splits the string (the chat message) into a table by a specified separator.

For example,

local split = string.split(chatMessage, "/")

Would split the chat message into a table where each key is the sentence separated by /. In this case, you could say detect the command the user typed in by indexing it as:

local command = split[1]

Make sure you get rid of the prefix by putting:

local command = split[1]:sub(2)

As for the player, you could index the table as

local player = split[2]

If you wanted to make an all command, again, you can make use of our split[2] argument, detect “all”, and pass a table of all players to your command.

You can most definitely make a separate module for commands, but I wouldn’t unless your familiar with how ModuleScripts work, you can read up on them here

Additionally, you can read up on string functions here. I recommend you take a look at these as they will help you through various different functions that your admin will need.

Good luck!


For this, you can just loop through all the players. Players:GetPlayers() returns an array you can loop through with ipairs.

Similarly, your best option is to loop through all players here. Instead of just running it for everyone, you can use string.sub and string.lower to shorten and lowercase their username and compare it once it’s the same length as the partial name. If it’s the same, break the loop.

ModuleScripts are a great way of organizing code. If it helps you, feel free to use them, but they are not ever necessary to use.

1 Like