i want to put a small wait every sentence writen while the effect is running here is my script
local textLabel = script.Parent
local function typewrite (object, text, text2, text3)
for i = 1,#text,1 do
object.Text = string.sub(text, 1, i)
wait(0.07)
end
end
typewrite(textLabel,"What was that? A Knife? What Could this possible be...?") -- for example i want it to be like this (typewrite(textLabel,"What was that? .wait(0.3) Knife? wait(0.3) What Could this possible be...?")
please tell me if iam not clear enough on what i want to achieve
You can make a list of punctuations and then if the character is a punctuation mark then we will pause, here’s an example:
local textLabel = script.Parent
local Punctuations = {["?"] = 0.3}
local function typewrite (object, text, text2, text3)
for i = 1,#text,1 do
object.Text = string.sub(text, 1, i)
if Punctuations[text[i]] then wait(Punctuations[text[i]]) end
wait(0.07)
end
end
typewrite(textLabel,"What was that? A Knife? What Could this possible be...?") -- for example i want it to be like this (typewrite(textLabel,"What was that? .wait(0.3) Knife? wait(0.3) What Could this possible be...?")
Instead of manually creating the string, try incrementing TextLabel.MaxVisibleGraphemes. It’s simpler and as an aside you avoid creating lots of strings which take up memory
There’s also a string pattern for matching punctuation characters, %p.
function typewrite(label, text)
label.MaxVisibleGraphemes = 0
for i = 1, #text do
label.MaxVisibleGraphemes += 1
local delay = text:sub(i, i):character:match("%p") and 0.3 or 0.07
task.wait(delay)
end
end
This can simply be text[i]. I also offered the punctuation table instead of string matching so they can get full control over the rest period for different punctuations.
Yeah, the added control is totally worth it. I’m also not sure what %p even matches, apparently it’s locale-dependent? Does that mean it matches different things on different players’ computers? xD Not that useful in this case tbh