Typewriter Effect but per word

  1. What do you want to achieve?
    Typewriter effect but instead of going every character it goes every word
  2. What is the issue?
    Every function I’ve tried has not been able to support line breaks consecutively or not
  3. What solutions have you tried so far?
  • ChatGPT
  • Code Assist
  • My own knowledge of scripting
  • Devforum searching

ChatGPT has given me this base function which I’ve tried to correct both myself and with ChatGPT

function typewriterEffect(label, text, delay)
    label.Text = ""
    
    local words = {}
    for word in text:gmatch("%S+") do --Problem is here, it does not recognize \n
        table.insert(words, word)
    end
    
    local function updateLabel()
        for i, word in ipairs(words) do
            if i > 1 then
                label.Text = label.Text .. " " .. word
            else
                label.Text = word
            end
            wait(delay or 0)
        end
    end
    
    spawn(updateLabel)
end

local words = string.split(text, ' ')

very frustrated with myself for not thinking of this

Not really sure how to implement both space and line break support efficiently, made this one liner for that.
string.split(table.concat(string.split(text, '\n'), ' '), ' ')

local lines = string.split(text, '\n')
text = table.concat(lines, ' ')
local words = string.split(text, ' ')

I did something like this

words = InputString:gsub("\n", " \n"):split(" ")
local OutputText = ""
for i = 1, #words do
    OutputText ..= table.concat(words, " ", 1, i) .. " "
    wait(delay)
end

(this was typed on mobile so yeah)