How to stop typing effect and then continue it

just a simple problem

i want to put a small wait every sentence writen while the effect is running here is my script

local textLabel = script.Parent

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

typewrite(textLabel,"What was that? A Knife? What Could this possible be...?") -- for example i want it to be like this (typewrite(textLabel,"What was that? .wait(0.3) Knife? wait(0.3) What Could this possible be...?")

please tell me if iam not clear enough on what i want to achieve

1 Like

You can make a list of punctuations and then if the character is a punctuation mark then we will pause, here’s an example:

local textLabel = script.Parent
local Punctuations = {["?"] = 0.3}

local function typewrite (object, text, text2, text3)
	for i = 1,#text,1 do
		
		object.Text = string.sub(text, 1, i) 
		 if Punctuations[text[i]] then wait(Punctuations[text[i]]) end
		
		wait(0.07)
	end
end

typewrite(textLabel,"What was that? A Knife? What Could this possible be...?") -- for example i want it to be like this (typewrite(textLabel,"What was that? .wait(0.3) Knife? wait(0.3) What Could this possible be...?")
1 Like

Also instead of resetting the whole text Everytime you can just concatenate the current letter on.

Replace:

With
object.Text ..= text[i]

Instead of manually creating the string, try incrementing TextLabel.MaxVisibleGraphemes. It’s simpler and as an aside you avoid creating lots of strings which take up memory :+1:

There’s also a string pattern for matching punctuation characters, %p.

function typewrite(label, text)
    label.MaxVisibleGraphemes = 0
    for i = 1, #text do
        label.MaxVisibleGraphemes += 1
        
        local delay = text:sub(i, i):character:match("%p") and 0.3 or 0.07
        task.wait(delay)
    end
end
2 Likes

This can simply be text[i]. I also offered the punctuation table instead of string matching so they can get full control over the rest period for different punctuations.

2 Likes

Yeah, the added control is totally worth it. I’m also not sure what %p even matches, apparently it’s locale-dependent? Does that mean it matches different things on different players’ computers? xD Not that useful in this case tbh

1 Like

dosent seem to work for some reason?

seem to be working thank you, i made an entire new script but thanks for the idea

1 Like

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