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

How to make words that type?

Asked by 8 years ago

Like I wanted to make something on my TextLabel that typed for example "Welcome to my place" but it typed out every letter to make the word. Can anyone help me?

1 answer

Log in to vote
0
Answered by
funyun 958 Moderation Voter
8 years ago
text = "Welcome to my place" --Some text to be "typed out" on the text label
textlabel =  --Place TextLabel object here

for i = 1, #text do
    textlabel.Text = string.sub(text, 1, i)
    wait(.1)
end

So, we make some text to be typed out. We create a variable for the TextLabel object. Then, we create a numeric for loop, running code for each character in the text. Each time we loop, we add one character to the TextLabel's text. string.sub returns a substring from the text between the second and third arguments. For example:

text = "Hello world!"
print(string.sub(text, 1, 5))

That prints out "Hello". A substring between "i" and "i" would be "W", "We", "Wel", "Welc"... and so on. We then wait for a 10th of a second between iterations to simulate realistic typing speed.

2
It's a bad idea to use `(i, i)` -- you should use `(1, i)`. Also remember how much cuter `text:sub(1, i)` is than `string.sub(text, 1, i)`! BlueTaslem 18071 — 8y
Ad

Answer this question