„string.split(/n)“ do not yelds

Hi, I understand scripting quite well, but I’m not very familiar with string patterns. I’m working on a plugin and I need to split multiline strings. Only this problem:

local String = [[v 1,1,1
v 2,2,2
v 3,3,3
v 4,4,4
v 5,5,5,
]]

local Table = string.split(String, "/n") --Split all line
for i,v in ipairs(Table) do
    wait(5)
    print(i,v)
end

For example, when I run this code here

Then the code waits for 5 seconds the first time, but after the second time it doesn’t even wait and it plays the whole thing. But I have to play every single line. How do I do that?

To use variables for what is returned by string.split() you would do this

local lineOne, lineTwo = string.split(String, "\n")[1], string.split(String, "\n")[2] .. etc.

This prints every line separately


local String = [[v 1,1,1
v 2,2,2
v 3,3,3
v 4,4,4
v 5,5,5,
]]  

for _,v in ipairs(String:split("\n")) do 
     print(v) 
     wait(5) 
end

Ok, i need to print all line separately (this was my question) but it need to yelds. It’s hard to explain this, so I used this code before, but it went wrong (instead of playing the loop normally, it only plays once and it gives me all the lines directly). And no, your method doesn’t work but thanks for trying (and no, I can’t use variables because firstly the string can always change and secondly mine has over 800 lines)

Yes, i am sure but it not was working

EDIT:
Wait yes, i am using another slash.

This is what i am using:

local Table = string.split(String, "/n")

And this is what you are using:

String:split("\n")

But this changes nothing, or yes?

Yes it does,

“/n” is not a pattern, use “\n” instead.

1 Like

Wow, i really did not know that this would make such an important difference, thank you very much.