Typewriter effect... but backwards

read until end

Hi! So, I made this game and in the main menu there is a section that displays tips. It uses a typewriter effect to type it out, but for some reason I can’t seem to make a typewriter effect that will untype it.

If you want me to clarify on the subject don’t hesitate to ask.

Any help is appreciated, thanks!

6 Likes

May you show your script doing the effects?

1 Like

Here it is:

For some reason, the UnWrite function just freezes the text.

2 Likes
local function typewrite(text)
    textLabel.Text = text
    for i = 1, #text do
        textLabel.MaxVisibleGraphemes = i
        task.wait(0.02)
    end
    textLabel.MaxVisibleGraphemes = -1
end

local function untypewrite()
    for i = #textLabel.Text, 0, -1 do
        textLabel.MaxVisibleGraphemes = i
        task.wait(0.02)
    end
    textLabel.MaxVisibleGraphemes = -1
    textLabel.Text = ""
end

I don’t know why you would need to untypewrite, but here.

2 Likes

Thanks! Btw, what does MaxVisibleGraphemes mean?

1 Like

It will only display x amount of characters from the start of the text. Everything else will pretend the text is still there.

1 Like

Ok, unfortunately, I ran into an error. It still just disappears instead of typing itself backwards. I’m really sorry but I can’t mark your answer a solution due to that error.

1 Like

They may have forgotten to specify the step. Try this:
for i = #textLabel.Text, 0, -1 do

The -1 just makes it count backwards.
(Please still give the solution to @bluebxrrybot)

1 Like

image

while the length of the text is < 0 ?

also yeah you should use the MaxVisibleGraphenes approach and try get it to work.

1 Like

UPDATE:

I fixed it!! YAY!

This worked perfectly fine.

This, however, must be replaced with:

local function untypewrite()
	for i = string.len(textLabel.Text), 0, -1 do
		textLabel.MaxVisibleGraphemes = i
		task.wait(0.05)
	end
	textLabel.MaxVisibleGraphemes = -1
	textLabel.Text = ""
end

Otherwise, the text just disappears after a few seconds.

2 Likes

Yes I admit that was pretty stupid.

2 Likes

You should use the # operator. It returns the length of tables and strings. string.len is most likely deprecated, or at least not used anymore. Sorry for forgetting to set the for loop increment to -1, I almost never use for loops that go backwards.

1 Like

No probs. Thanks for letting me know about the deprication.

1 Like

Please don’t avoid it. It’s not a deprecated function. Hashtag before a string and string.len do the same thing. It’s just preference.

Could somebody please help me with this

click here

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.