Debounce help please

Can someone show me why this debounce isnt working? It appears to be in the correct place to me.

local say = {"text here"}
local debounce = false

if debounce then return end
debounce = true

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	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

this should be inside of the function like this

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	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)
2 Likes

Thanks for that help. Simple things. haha