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
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")
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.