This is for an admin script. How do I have it search for the second space? So like ``;;setHealth [Player] [newHealth]" I cant figure out how to have the script 'know' what part is the name and what part is the value that the health will be set to
String patterns are just what you need. I recommend splitting the string after the signal character(s) (in your case, the ";;") into a command and argument.
01 | local SignalCharacters = ";;" |
02 | local Message = ";;setHealth Username 100" |
03 |
04 | function HandleMessage(Message) |
05 | if Message:sub( 1 , #SignalCharacters) ~ = SignalCharacters then |
06 | -- Return early if message isn't a command |
07 | return |
08 | end |
09 |
10 | local CommandSubstring = Message:sub(#SignalCharacters + 1 ) |
11 |
12 | local Command = nil |
13 | local Arguments = { } |
14 |
15 | for Match in CommandSubstring:gmatch( "%w+" ) do |