Looping typewriter effect

Hello! My first time using devforum and a beginner at scripting.

I’m currently using AlvinBlox’s text typewriter effects link and currently using it for a dialogue triggered with proximityprompt between an NPC and a player.

I used a loop system to keep on track of the currentpage. This currentpage is a variable which defaults to 1 and every time the player presses the “NEXT” button, it adds 1 and triggers the next dialogue.

currentpage = 1

Here’s a portion from the loop

while wait() do
	if currentpage == 1 then
		typewrite(messageHolder, "I'm tired...")
		nameLabeler.Text = currentnpc
	elseif currentpage == 2 then
		typewrite(messageHolder, ".... Are you perhaps, Shiba?")
		nameLabeler.Text = plr.Name

The issue is that the typewriter effect keeps on repeating together the loop. Already tried using it without a loop but the next dialogue can’t be triggered.
Here’s the video of the issue:
robloxapp-20211206-0212031.wmv (864.7 KB)

What I want to happen is that the typewriter effect won’t keep on a loop.

You can try using an event-based system.

local currentpage = 0

function Typewrite()
    currentpage = currentpage + 1

    if currentpage == 1 then
		typewrite(messageHolder, "I'm tired...")
		nameLabeler.Text = currentnpc
	elseif currentpage == 2 then
		typewrite(messageHolder, ".... Are you perhaps, Shiba?")
		nameLabeler.Text = plr.Name
    end
end

NextButton.Activated:Connect(Typewrite)