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!
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