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

Message Typewriter effect but won't reverse?

Asked by
Mayk728 855 Moderation Voter
7 years ago

I have a script that would make the text have a sort of typewriter effect. The only problem i have is that i don't know how to get it to reverse.

local String = "Hello World!"
local Length = string.len(String)

for i=1,Length do
script.Parent.Text = (string.sub(String,1,i))
wait(0.06)
end

wait(2)

local String = "Hello World!"
local Length = string.len(String)

for i=1,Length do
script.Parent.Text = (string.sub(String,-1,i)) --Negative 1 instead of 1
wait(0.06)
end

I put -1 instead of 1 but all it did was make the text disappear altogether instead of having that effect in reverse. Any help would be appreciated!

1 answer

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

You could reverse the string using the string.reverse function, then apply the sub function with arguments of the current iteration, and reverse it again :)

This would produce the effect you're looking for.

local String = "Hello World!"

--The # operator returns the length of tables and strings.
for i = 1,#String do
    --You can invoke the string.sub function as a method.
    script.Parent.Text = String:sub(1,i)
    wait(0.06)
end

wait(2)

for i = 1,#String+1 do --+1 to account for the first letter.
    --Reverse it, sub it, reverse again.
    script.Parent.Text = String:reverse():sub(i):reverse();
    wait(0.06)
end
0
Thank you! Mayk728 855 — 7y
Ad

Answer this question