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

How to make a text gradually make a sentence?

If I had a string, how would I make the text gradually a string? This is an example I wrote with an array:

String = ["T", "h", "i", "s"]  -- etc

for i in String do
	Text.Text = String[1, i] -- Makes string's text every value from 1 to i
	wait(0.05)
end

This [should] work[s]. But how can I do it with a string? Instead of lots of stings in an array>

String = "This is an example!"
Text = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Text

for i in String do
	Text.Text = i
	wait(0.05)
end

This only makes it the letter one at a time (I think, I can't currently test it) Would I have to put it in an array or is it achievable with a string?

1 answer

✓ Accepted answer

You can't do String[1, i]. If it did work it would probably mean the first element, and then the ith element (as a tuple).


To accumulate the first i elements of String, you would need a loop:

local s = "" -- accumulator
for j = 1, i do
	s = s .. String[j]
end

This is unnecessary, though. Lua provides the :sub function which facilitates what you originally wanted:

String:sub(1, i) -- the first i characters

Thus, you just have to change len repeatedly to see the first len characters of the list:

local text = "This is a message."
for len = 1, #text do
	print(text:sub(1, len))
end
-- T
-- Th
-- Thi
-- This

-- etc...

1 comment

0

Thanks, about your original statement; you can do this in Python, so I tried in Lua, thank you for the detailed explaination

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