Hello! I am attempting to make a function that loops through string.split(), but it does not look like the loop is picking up the result. What do I want to achieve?
I am attempting to make a function that converts a string with commas into an array. Here is an example: "Test 1,Test 2,Test 3"{"Test 1", "Test 2", "Test 3"} What is the issue?
The output of the function is always: What solutions have I tried so far?
I have tried to look up solutions on the DevForum, but there are no answers that help!
The Code
Script
function CommaStringToArray(InputString)
print(InputString) -- This will print the InputString parameter correctly!
local ArrayResult = {}
for CurrentIndex, CurrentString in pairs(string.split(InputString, ",")) do
print(CurrentString[CurrentIndex]) --> nil
table.insert(ArrayResult, CurrentString[CurrentIndex])
end
return ArrayResult
end
print(CommaStringToArray("Test1,Test2,Test3")) --> nil
print(CommaStringToArray("Test")) --> nil
Hello, @AstraI_YT!
This was because I was most likely going to add more to the function. I am curious as to why looping string.split() does not function and returns nil values. I will mark your reply as the solution because it works as intended, thank you! It looks like looping string.split() is not possible.