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

What would I do to make this script shorter?

Asked by 9 years ago

I remember seeing something on wiki where you could find the text length of a string, I don't remember it clearly, so here is an example of what I have

script.Parent.Text = "g"
wait(1)
script.Parent.Text = "ge"
wait(1)
script.Parent.Text = "get"
----ETC.-------

1 answer

Log in to vote
6
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

We can get pieces of a string, called substrings using the sub method:

msg = "Hello there"
script.Parent.Text = msg:sub(1,5) -- get characters 1 to 5 (inclusive)

There are #msg characters in msg (# is a unary operator for string length as well as table length) so a loop could look like this:

for i = 1, #msg do
    script.Parent.Text = msg:sub(1, i)
    wait(1)
end
0
I would like to add that you can also use the len() method to get the LENgth of a string. Perci1 4988 — 9y
Ad

Answer this question