Get part of a string based on the spaces next to it

Essentially, I am creating a command system, and want to detect when the actual command stops and the player starts typing arguments into the command bar.

For example, the command “kill” would be the command, and “kill (player)” would be the argument.

The only problem I’m facing is that I don’t know how to detect these arguments. Basically, I want the computer to go “there is a space here, this is a separate argument, the spaces after here are other arguments.”

Any help would be appreciated!

You can use string.split for this, this is also in many other languages so it’s something to remember (saves so much time!)

in this case our input is
“KILL Certified_Nooby”

passing that through string.split("KILL Certified_Nooby"," ") will return the values that you need.

I forgot to mention this outputs a table, so looking up [1] will output “kill” and [2] will output “certified_nooby”

Thank you! I read more about it on the official Roblox documentation and it works like a charm in my game.

1 Like