Weird dialogue bug

I making a small collect quest system and there is a weird bug esseintially you get the quest by talking to an npc and once its done with its dialogue a button pops up for you to accept the quest but for some reason its popping up before the npc finishes it’s dialogue

Code:

local DialogueRemote = game.ReplicatedStorage.Remotes.Dialogue
local Player = game.Players.LocalPlayer

local DialogueGui = Player.PlayerGui.Dialogue
local QuestGui = Player.PlayerGui.QuestGui
local NameBox = DialogueGui.Container.NpcName

local QuestModule = require(game.ReplicatedStorage.QuestModule)
local TweenModule = require(game.ReplicatedStorage.TweenModule)
local InteractFrame = DialogueGui.Container.InteractFrame
local TextButton = script.Parent
local Quest 

DialogueRemote.OnClientEvent:Connect(function(QuestNum, NpcName)
	DialogueGui.Enabled = true
	NameBox.Text = NpcName
	
	local QuestString = QuestModule.QuestList[QuestNum]
	Quest = QuestModule.Quests[QuestString]
	
	
	TweenModule.TweenGui(DialogueGui.Container, {Position = UDim2.new(0.246, 0, 0.6, 0)}, 0.10)
	
	local textlabel = DialogueGui.Container.Frame.TextLabel
    local text = ("I want you to " .. Quest.Name .. " good luck")
	print(text)
	
	InteractFrame.Visible = true
	TextButton.Text = "Ok"
	
	
		for i = 1, #text, 1 do
			textlabel.Text = string.sub(text, 1, i)
			wait(0.027)
			print("hi")
		end
		
		print("done")
	InteractFrame.Visible = true
	TextButton.Text = "Ok"
	
end)

TextButton.MouseButton1Down:Connect(function()
	DialogueGui.Enabled = false
	InteractFrame.Visible = false
end)

btw interact frame is the button to accept the quest