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?
You can't do String[1, i]
. If it did work it would probably mean the first element, and then the i
th 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...