Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to I make my text change to my next bit of text?

Asked by
bailley5 114
4 years ago
local text = "Hello Rats!"
wait(2)
local text = "Yeah haw" -- This is my Text.




for i = 1, #text do
    script.Parent.Text = string.sub(text, 1, i)
    wait(0.04) -- Speed of the text Typewriter animation
end

2 answers

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

You could put the sentences in a table and loop through the table.

--table containing all the sentences
sentences = {
    "Hello Rats!",
    "Yeah haw",
    "This is another sentence!"
}


--Displays current sentence with type writer effect
function displaySentence(sentence)
    for i = 1, #sentence do
        script.Parent.Text = string.sub(sentence, 1, i)
        wait(0.04) -- Speed of the text Typewriter animation
    end
end


--loop thru all the sentences, displaying each sentence 
--with a 1 second pause in between each sentence
for _, sentence in pairs(sentences) do
    displaySentence(sentence)
    wait(1)
end
0
It says in the output 17:35:22.266 - Players.bailley5.PlayerGui.ScreenGui.TextLabel.Script:12: bad argument #1 to 'sub' (string expected, got nil) bailley5 114 — 4y
0
my bad, text should be sentence i fixed that royaltoe 5144 — 4y
0
Thanks bailley5 114 — 4y
Ad
Log in to vote
0
Answered by
bailley5 114
4 years ago

Answered

Answer this question