So I'm making my own admin commands and I am trying split chat messages by words using string.gsub() . I'm not sure how fully string.gsub() actually works but I know I have to use a string pattern to seperate the strings by spaces.
Someone told me a way to split/iterate through a string was like this:
local SpliceResult = {}
for word in string.gsub(ChatMessage, "%S+") do -- This is line 103
table.insert(SpliceResult, word)
end
-- %S+ is a string pattern for seeing spaces in strings
-- ChatMessage is a variable for what the player said in chat
-- SpliceResult is a table holding the strings seperated into more strings by spacing
Now, it gives me a error that tells me of a "bad argument". So with my knowledge I may of put something other than a string, function or table. Here what it says directly:
ServerScriptService.AdminManager.CommandsModuleScript:103: bad argument #3 (string/function/table expected)
Since this is a function inside the admin scripts I checked and the parameters are all right. I'm not sure why the output gives a "bad argument" even though a ChatMessage is a string. I tested it and it's a string since I print debugged by saying:
print(type(ChatMessage))
--> string
If there is any other way to split and iterate a string you can tell me in the comments section

1 comment
Thank you sorry for replying late I'll try it and see if it works