What I have below is a little snippet of code for a GUI dialogue system. It's using a typewriter effect. The problem is if the player spams the button to skip the text, text starts overlapping and it gets really weird, this is a bit of it:
for i = 1, #text do
gui.Dialogue.DialogueBox.Text.Text = string.sub(text, 1, i)
wait()
end
What I'm trying to do is have the script ask for each iteration of the for loop if the player is pressing "MouseButton1Down" or just clicking at all, so that I can break the for loop and go on to the next section of code which is supposed to be another one of these loops, just with different dialogue of course.

3 comments
That's not how events work.
Oh so... I have to edit the code...
I don't think you understand what you're doing. Please at least test your method before posting an answer. If you're not knowledgeable on the issue's concept it's fine to not attempt answering and instead learn it beforehand.