I want to modify one of my scripts (Which reveals a TextLabel’s message 1 character at a time) so that I can add custom pauses and intervals at certain points such as a longer wait for each dot in the text.
This is what the script looks like currently:
local TextLabel = script.Parent
local message = "What happened?... Where am I?..." -- put your full message here
task.wait(8)
TextLabel.Visible = true
for i = 1, #message, 1 do
print(i)
TextLabel.Text = string.sub(message, 1, i)
task.wait(0.05)
end
I’ll be honest, I don’t completely understand the script I’m using, but I seem to understand a good part of it. It could possibly take a simple modification, or it could take a completely different script.
My best guess would be to modify the for loop so it only puts out a certain amount of characters, then create a duplicate of it with a different amount of time waited between adding on a new character, or just a line in between the for loops for a singular pause.
You can simply create a dictionary that holds the wait time (in seconds) of the character (being the index). For example:
local charWaits = {
["."] = 0.2,
[":"] = 0.1
}
for i = 1, #message, 1 do
print(i)
TextLabel.Text = string.sub(message, 1, i)
-- Gets the wait time from the dictionary, or uses the default 0.05 seconds
local currentChar = string.sub(message,i,i+1)
local waitTime = charWaits[currentChar] or 0.05
task.wait(waitTime)
end
Also, instead of using string.sub to set the text, you can use the MaxVisibleGraphemes property to control how many characters are shown at once, but it’s up to you.
This is the output:
18:03:27.842 1 - Server - Message1:12
18:03:27.843 Wh - Server - Message1:18
18:03:27.844 nil - Server - Message1:19
18:03:27.910 2 - Server - Message1:12
18:03:27.911 ha - Server - Message1:18
18:03:27.911 nil - Server - Message1:19
18:03:27.976 3 - Server - Message1:12
18:03:27.977 at - Server - Message1:18
18:03:27.977 nil - Server - Message1:19
18:03:28.043 4 - Server - Message1:12
18:03:28.044 t - Server - Message1:18
18:03:28.044 nil - Server - Message1:19
18:03:28.110 5 - Server - Message1:12
18:03:28.111 h - Server - Message1:18
18:03:28.111 nil - Server - Message1:19
18:03:28.176 6 - Server - Message1:12
18:03:28.177 ha - Server - Message1:18
18:03:28.177 nil - Server - Message1:19
18:03:28.243 7 - Server - Message1:12
18:03:28.244 ap - Server - Message1:18
18:03:28.244 nil - Server - Message1:19
18:03:28.309 8 - Server - Message1:12
18:03:28.310 pp - Server - Message1:18
18:03:28.310 nil - Server - Message1:19
18:03:28.376 9 - Server - Message1:12
18:03:28.377 pe - Server - Message1:18
18:03:28.377 nil - Server - Message1:19
18:03:28.442 10 - Server - Message1:12
18:03:28.443 en - Server - Message1:18
18:03:28.443 nil - Server - Message1:19
18:03:28.509 11 - Server - Message1:12
18:03:28.510 ne - Server - Message1:18
18:03:28.510 nil - Server - Message1:19
18:03:28.576 12 - Server - Message1:12
18:03:28.577 ed - Server - Message1:18
18:03:28.577 nil - Server - Message1:19
18:03:28.643 13 - Server - Message1:12
18:03:28.645 d? - Server - Message1:18
18:03:28.645 nil - Server - Message1:19
18:03:28.709 14 - Server - Message1:12
18:03:28.710 ?. - Server - Message1:18
18:03:28.711 nil - Server - Message1:19
18:03:28.776 15 - Server - Message1:12
18:03:28.778 … - Server - Message1:18
18:03:28.778 nil - Server - Message1:19
18:03:28.843 16 - Server - Message1:12
18:03:28.844 … - Server - Message1:18
18:03:28.844 nil - Server - Message1:19
18:03:28.909 17 - Server - Message1:12
18:03:28.910 . - Server - Message1:18
18:03:28.911 nil - Server - Message1:19
18:03:28.976 18 - Server - Message1:12
18:03:28.977 W - Server - Message1:18
18:03:28.977 nil - Server - Message1:19
18:03:29.044 19 - Server - Message1:12
18:03:29.045 Wh - Server - Message1:18
18:03:29.045 nil - Server - Message1:19
18:03:29.109 20 - Server - Message1:12
18:03:29.110 he - Server - Message1:18
18:03:29.110 nil - Server - Message1:19
18:03:29.176 21 - Server - Message1:12
18:03:29.177 er - Server - Message1:18
18:03:29.177 nil - Server - Message1:19
18:03:29.243 22 - Server - Message1:12
18:03:29.244 re - Server - Message1:18
18:03:29.245 nil - Server - Message1:19
18:03:29.309 23 - Server - Message1:12
18:03:29.310 e - Server - Message1:18
18:03:29.310 nil - Server - Message1:19
18:03:29.376 24 - Server - Message1:12
18:03:29.377 a - Server - Message1:18
18:03:29.377 nil - Server - Message1:19
18:03:29.442 25 - Server - Message1:12
18:03:29.443 am - Server - Message1:18
18:03:29.443 nil - Server - Message1:19
18:03:29.509 26 - Server - Message1:12
18:03:29.510 m - Server - Message1:18
18:03:29.510 nil - Server - Message1:19
18:03:29.576 27 - Server - Message1:12
18:03:29.578 I - Server - Message1:18
18:03:29.578 nil - Server - Message1:19
18:03:29.643 28 - Server - Message1:12
18:03:29.645 I? - Server - Message1:18
18:03:29.645 nil - Server - Message1:19
18:03:29.709 29 - Server - Message1:12
18:03:29.710 ?. - Server - Message1:18
18:03:29.711 nil - Server - Message1:19
18:03:29.776 30 - Server - Message1:12
18:03:29.777 … - Server - Message1:18
18:03:29.777 nil - Server - Message1:19
18:03:29.842 31 - Server - Message1:12
18:03:29.844 … - Server - Message1:18
18:03:29.844 nil - Server - Message1:19
18:03:29.909 32 - Server - Message1:12
18:03:29.910 . - Server - Message1:18
18:03:29.911 1 - Server - Message1:19
Oh that’s my bad, change local currentChar = string.sub(message,i,i+1) to local currentChar = string.sub(message,i,i), I made it grab the current and next character, instead of just the current character lol.
It works the same, just instead of changing the Text property, you set the MaxVisibleGraphemes property to i:
TextLabel.Text = message
TextLabel.MaxVisibleGraphemes = 0
for i = 1, #message, 1 do
TextLabel.MaxVisibleGraphemes = i
-- Gets the wait time from the dictionary, or uses the default 0.05 seconds
local currentChar = string.sub(message,i,i+1)
local waitTime = charWaits[currentChar] or 0.05
task.wait(waitTime)
end