Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

3 comments

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)

0

my bad, text should be sentence i fixed that

0

Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.