So I get that you can use string.sub to check if the player's first few letters are a prefix, and then you can use whatever they say after that as a player's name, or whatever.
But how exactly do you find out where the second word ends? I mean, let's say I wanted to make a command that would forcefield a player for a duration of time
:ff bluehawks 20
How would I actually get the third word? In this case it's a number, but what if it wasn't?
So you can use string.split method for strings that roblox has implemented.
Here's an example
game.Players.PlayerAdded:Connect(function(plr) plr.Chatted:Connect(function(msg) local ThirdWord = msg:split(" ")[3] --Splitting the message which returns an array --[[ Here is just extra because I feel like it if typeof(ThirdWord) == "number" then --Checking if it's a number --Do your thing end ]] end) end)
If you are more visual let me show you something here
local Message = ":ff uhi_o 40" local Words = Message:split(" ") --Returns an array like so {":ff", "uhi_o", "40"} local ThirdWord = Words[3] --Getting the third element
Just split the strings.
local Message = ":ff bluehawks 20" function Split(Command, Separator) Seperator = Seperator or "%s" Arguments = {} for String in Command:gmatch("([^"..Seperator.."]+)") do table.insert(Arguments, String) end return Arguments end local Duration = Split(Message)[2]
See this: https://stackoverflow.com/questions/1426954/split-string-in-lua