How to make string.sub/typewriter effect pause at punction marks?

So lets say I have text like:
“Hi! Player!”
using string.sub it’d make each character appear one by one, but how would i make it pause for a bit at punction marks such as (.) (,) (!) (?)

local Text = "Hi! Player!"
for i = 1, #Text do
        Dialogue.Text = string.sub(Text,1,i)
		wait(0.02)	
end
1 Like

already made this, I just modified it a bit

3 Likes

Hi again! how would I incorporate audio into this? Like for every character that appears a sound plays?

local TextLabel = -- change
local Sound = -- change

local function typewriter(s : string)
	for i=1, string.len(s) do
		local text = string.sub(s, 1, i)

		TextLabel.Text = text
		
		if string.sub(s, i, i) ~= " " then
			Sound:Play()
		end

		if string.sub(s, i, i) == "," then
			task.wait(0.3)
		elseif string.sub(s, i, i) == "." then
			task.wait(0.4)
		elseif string.sub(s, i, i) == "!" then
			task.wait(0.5)
		elseif string.sub(s, i, i) == "?" then
			task.wait(0.3)
		else
			task.wait(0.05)
		end
	end
end

typewriter("AAAAAAAAAAAAAAAAAAAAAAAAAAAA")
2 Likes

Just make sure to use ContextText (instead of Text) and MaxVisibleGraphemes (instead of subbing a string) or else you might face some problems with the typewriter effect.