I need help with splitting string, a player enters command and then it should split to 3 parts seperated by space, I only managed to split 2, and 3rd just returns nill, how can I make that and select 2nd and 3rd parts?
3 Likes
Can you send the script? Also, are you using split()
?
Try doing
local SplittedString = string.split(string.lower(YOURSTRING), " ")
now you can acces splitted strings like this:
SplittedString[1] = ...
SplittedString[2] = ...
SplittedString[3] = ...
etc.
Example:
local String = "Tp all garden" -- what player said
local SplittedString = string.split(string.lower(String), " ")
if SplittedString[1] ~= nil and SplittedString[1] == "tp" then
if SplittedString[2] ~= nil and SplittedString[2] == "all" then
if SplittedString[3] ~= nil and SplittedString[3] == "garden" then
-- rest of the code
end
end
end
If you are using something like that, as demonstrated in @FilipBylbo 's code snippet, remember that Luau’s index starts at 1 and not 0, unlike other programming languages.