Dialog Script Help

This dialog script works properly, but If I try to talk to someone and then talk to someone else while the script is running, the script will no longer work.

I am at a loss on how to stop this from happening. Each NPC, has this script in his character.

local say = {"Text Here"}
local debounce = false
local sound = script.Parent.talk

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	sound:Play()
	if debounce then return end
	debounce = true
	plr.PlayerGui.NpcChatGui.NpcName.Text = script.Parent.Name
	plr.PlayerGui.NpcChatGui.Enabled = true
	for i, v in pairs(say) do
		for i = 1, string.len(v) do wait(0.035)
			plr.PlayerGui.NpcChatGui.NpcText.Text = string.sub(v, 1, i)
		end
		wait(string.len(v) / 10)
	end
	plr.PlayerGui.NpcChatGui.Enabled = false
	debounce = false
end)

Thanks in advance.

1 Like
local say = {"Text Here"}
local debounce = false
local sound = script.Parent.talk

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
    if plr.PlayerGui.NpcChatGui.Enabled then return end
	sound:Play()
	plr.PlayerGui.NpcChatGui.NpcName.Text = script.Parent.Name
	plr.PlayerGui.NpcChatGui.Enabled = true
	for i, v in pairs(say) do
		for i = 1, string.len(v) do wait(0.035)
			plr.PlayerGui.NpcChatGui.NpcText.Text = string.sub(v, 1, i)
		end
		wait(string.len(v) / 10)
	end
	plr.PlayerGui.NpcChatGui.Enabled = false
end)
1 Like

You are a champion among men. Thanks. That worked perfectly.

I think a bool value outside of the script would be a great solution. Set it to true if a player is talking to an NPC, then set it to false if the player is not talking to an NPC or the player is done talking to an NPC.

Then make an “if then” statement to check if the player is able to talk to an NPC.
( you would put the if statement below the function )

Hope this helped.

1 Like