Is it possible to check for a specific symbol with a typewriter effect utilizing MaxVisibleGraphemes?

I’m currently using the below code for my typewriter effect, and it works fine. But I want to find out a way of adding pauses in between, like at commas and periods. Is there any way of checking for a symbol inside a string using this method?

local function typewriter(label, text : string, FX : Sound)
	label.Text = text
	label.MaxVisibleGraphemes = 0
	
	for i = 1, text:len() do 
		isWriting = true
		FX:Play()
		label.MaxVisibleGraphemes += 1
		task.wait(.04)
	end
	
	isWriting = false
end

Thank you.

local function typewriter(label, text : string, FX : Sound)
	label.Text = text
	label.MaxVisibleGraphemes = 0

	local pauseLength = 0.04 -- length of pause in seconds
	
	for i = 1, text:len() do
		isWriting = true
		FX:Play()
		label.MaxVisibleGraphemes += 1
		
		-- Check for comma or period
		if string.find(text, "[,.]", label.MaxVisibleGraphemes) then
			task.wait(pauseLength * 2) -- pause for twice as long
		else
			task.wait(pauseLength) -- pause for normal length
		end
	end
	
	isWriting = false
end

You can use string.sub to get a substring of your text, and then use string.find to check if the substring contains a comma or a period.
local function typewriter(label, text : string, FX : Sound)
local i = 0
label.Text = text
label.MaxVisibleGraphemes = 0
while i < text:len() do
local subtext = string.sub(text, 1, i+1)
if subtext:find("[,.]") then
task.wait(1)
end
isWriting = true
FX:Play()
label.MaxVisibleGraphemes += 1
task.wait(.04)
i = i + 1
end
isWriting = false
end

This just pauses the text for pauseLength * 2 until it passes the comma.

No it does not you silly goose

Please be respectful.
If you are going to use ChatGPT, please use it with care.

Im not using ChatGPT you silly goose

Uhh… stop calling me a silly goose?
Your solution does not work. If you are unable to help further, please stop replying.

I swapped it out for a string.sub() method.

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