Check for the last letter in substring

Hi again. I couldn’t think of a good way to explain my question in the title so I’ll explain it here: So I have a simple “typewriter” script, right?

for i = 1, #text do
	task.wait(1/charPerSecond)
	TextLabel.Text = string.sub(text, 1, i)
end

So this basically adds another character to the text each time it loops, essentially making a typewriter effect. How would I be able to know the last character the loop inserted? So if I were to add a print function in the for loop, it would output something like this:

H
e
l
l
o

i feel like i didnt explan ths well enough idk i feel braindead. please just ask if you need more clarification

If I understood correctly, do an if statement to check if i == #text

something like this is what I intend on doing


Like in the clip, it will basically just takes the last letter in the text every time it loops. I’m pretty sure it has something to do with sub.string but I can’t find anything on it that contributes to the solution I’m looking for

In that case, you can do string.sub(text, i, i). This should give you the last character typed in the text.

1 Like

Are you looking for something like this? It appears to already been an existing DevForum post.

1 Like

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