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)