How to make a text go "backwards"?

Yes, I know the title didn’t make sense.

I have this function here, made by @Alvin_Blox.

local function typewrite (object , text)
	for i = 1,#text,1 do
		object.Text = string.sub (text,1,i)
		wait(0.05)
	end
end

This basically just types something in the style of a typewriter, or just typing.

And I was looking to know how to make the text undo? Like, once it’s typed out text, it will undo it in the same typewriting effect…

I don’t really know how to explain it lmao.

Simply change the for loop to be decrementing from the full text to 0, than incrementing from 0 to the full text:

local function typewrite (object , text)
    -- incrementing
	for i = 1,#text,1 do
		object.Text = string.sub (text,1,i)
		wait(0.05)
	end

   -- decrementing
   for i = #text, 0, -1 do
       object.Text = string.sub(text, 1, i)
       wait(0.05)
   end
end
3 Likes

Or alternatively use string.reverse and loop as normally. It works about the same.

local function typewrite (object , text)
	for i = 1, #text, 1 do
		object.Text = string.sub(string.reverse(text), 1, i)
		wait(0.05)
	end
end
3 Likes