Search code examples
stringluaroblox

how can i convert a string to a list to index using a for loop in lua?


i'm trying to make a roblox game and i need a gui that shows text character by character but it just shows numbers this is my code

local frame = script.Parent.Parent
local currentText = ""
frame.Visible = false

local function showText (text, delayBetweenChanges)
    frame.Visible = true
    for letter in string.split(text,"") do
        local currentText = (currentText .. letter)
        script.Parent.Text = currentText
        wait(delayBetweenChanges)
    end
end

i thought it would add the next character to the already existing string and then display the final string

but it showed a number correlating to the position of that character in the string


Solution

  • local label=script.Parent
    local frame=label.Parent
    frame.Visible=false
    local function showText (text,delayBetweenChanges)
        frame.Visible=true
        label.Text=""
        for _,letter in ipairs(text:split"")do
            label.Text=label.Text..letter
            wait(delayBetweenChanges)
        end
        --frame.Visible=false
    end