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
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