How to Make typewriter wait for specific signs?

Hi, someone knows how could i do this typewriter wait for custom signs?, Based on a table

function Module.Typewrite(TextLabel: TextLabel, Text: string, DelayBetweenChars)
	local DisplayText = Text
	
	DisplayText = DisplayText:gsub("<br%s*/>", "\n")
	DisplayText:gsub("<[^<>]->", "")
	
	TextLabel.MaxVisibleGraphemes = 0
	TextLabel.Text = DisplayText
	
	local Index = 0
	
	if _G.CurrentCoroutine then
		coroutine.close(_G.CurrentCoroutine)
		_G.CurrentCoroutine = nil
	end
	
	task.wait()
	
	local punctuations = {
		[","] = 1
	}
	
	_G.CurrentCoroutine = coroutine.create(function()
		for First, Last in utf8.graphemes(DisplayText) do
			Index = Index + 1
			warn(Index, First, Last)
			TextLabel.MaxVisibleGraphemes = Index

			task.wait(DelayBetweenChars) -- or the signs, but i need a way to find or know the text index using MaxGraphmes
		end
		warn("Finished")
	end)
	
	if _G.CurrentCoroutine then
		coroutine.resume(_G.CurrentCoroutine)
	end
	
	
end

Use string.sub to determine the actual character, then just look for the char in the table

for First, Last in utf8.graphemes(DisplayText) do
	Index = Index + 1
	warn(Index, First, Last)
	TextLabel.MaxVisibleGraphemes = Index

	local Char = string.sub(Display, First, Last)
	if punctuations[Char] then
		task.wait(punctuations[Char])
	else
		task.wait(DelayBetweenChars)
	end
end
1 Like

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