How To Do Admin Commands

How are you suppose to use the various string functions to create admin commands?

How do you figure out which player/value is being referred to in a piece of text?

Any helpful sources?

1 Like

This is probably the best resource to start with:

I recommend working with the Lua chat system over any other method of listening to chat messages, as it provides a pretty nice interface for affecting both the game and the output chat messages.

You can create Command Functions that will swallow messages that meet a command format, and execute code on the server. The link above has a nice example for how these work. In my game I create a table of command functions that I then register with ChatService in a loop.

You can also create Filter Functions that can affect the appearance and content of a chat message (ie. message color, text). I have a decent example of a Filter Function here: Color Chat and Admin List - Roblox


Is there a source of how to use string patterns?

String patterns in Lua are yikes, but here are some resources I’ve used.

Why do you need complex patterns?

1 Like

I need a way to split up a command string

for example

"set ninja900500 level 500"

I need to split that up into 4 parts

I use this code for one of my commands. Doesn’t need to be complicated.
(%S+) matches a word, and (.+) matches anything from that point onwards.

local a,b,playerName,property,value = string.find(message, "/cmd (%S+) (%S+) (.+)")
1 Like

If you want to have simple admin commands you can match out the command itself and then match out the arguments and do something like this

if funcs[cmd] then
    ran,returns = pcall(funcs[cmd],sender,unpack(args))

and an example command could be

funcs.kill = function(sender,target)
    if isList(target) then
        local targets = listify(target)
        for _,playername in next,targets do

Tutorial I made a while ago. Might be helpful :wink:

1 Like