Weird sort of delay to clicking a button

So I have this mechanism of giving players permission to talk to NPCs by duplicating a given DialogueGui that is in the NPC’s model to the player’s PlayerGui and it prompts them dialogue and buttons to speak to them. However, the problem is that there’s a delay of some sort when you try to talk to them. I have to click several times to actually get the after-dialogue and it’s confusing on why it happens.

script 1 (gui giver):

local Nikalis = script.Parent
local ClickDetector = Nikalis.ClickDetector

local TypeWriter = require(game.ReplicatedStorage:WaitForChild("TypeWriter"))

ClickDetector.MouseClick:Connect(function(player)
	local character = player.Character
	
	if not player.PlayerGui:FindFirstChild("DialogueGui") then
		local DialogueGui = Nikalis.DialogueGui:Clone()
		DialogueGui.Parent = player.PlayerGui
		
		DialogueGui.NPCName.Text = "Nikalis"
		TypeWriter.typeWrite(DialogueGui.DialogueText, "Hello.. can I help you with something?")
	end
end)

script 2 (button click):

local GuiButton = script.Parent
local ScreenGui = GuiButton.Parent

local TypeWriter = require(game.ReplicatedStorage.TypeWriter)

local hasClicked = false

GuiButton.MouseButton1Down:Connect(function()
	if not hasClicked and ScreenGui.DialogueText.Text == "Hello.. can I help you with something?" then
		hasClicked = true
		
		TypeWriter.typeWrite(ScreenGui.DialogueText, "It's not that much of a climb..")
		
		local Option1 = ScreenGui.Option1
		Option1.Text  = "Bye."
	end
end)

I’m assuming the typeWrite function takes each character in the string provided and subs it into the string and then updates the dialogue text? If so the issue could lie in the fact that you aren’t able to click until this condition is met which won’t be met until it is fully typed out. Please correct me if I am wrong on how the typeWrite function works.

ScreenGui.DialogueText.Text == "Hello.. can I help you with something?"
1 Like

Weird, I just tried it out in the normal ROBLOX game and the delay disappeared. Thank you for the help though, very much appreciated!

No problem, glad you were able to figure it out!

1 Like