Need help with debouncing event!

Someone told me to debounce this, well i have no idea how becouse this script will only run once

wait(5)

script.Parent.Triggered:Connect(function(player)

local npcDialogueFrame = player.PlayerGui.MainGui.NpcDialogueFrame

**if npcDialogueFrame.Visible == false then** **-- this is where it stops the second time**
	
	
	local randomDialogueText = {"Hi, what do you want?", "Hi!", "Hello!", "Hello, what do you want?", "Hi, what do you need?", "Hello, what do you need?", "Please be fast, I'm in a hurry!", "Hello, please be fast, I'm in a hurry!", "Hi, please be fast I'm, in a hurry!"}
	
	local deez = randomDialogueText[math.random(1,#randomDialogueText)]

	npcDialogueFrame.NpcDialogueText.Text = deez
	
	npcDialogueFrame.Visible = true

	for i = 1,#deez do
		npcDialogueFrame.NpcDialogueText.Text = string.sub(deez, 1, i)
		wait(0.05)
	end
end


end)

btw i also have another script that makes is disapear when you click a button in the dialogueFrame

You would probably not need a debounce for what you are doing seeing that it cant run while the GUI is visible.

But why is it not working then?

What exactly isn’t working for you?

The first time it works but the second time it does not when i trigger the proximity promt it stops where i said it in the script at my post.

Could I have a look at the other script?

sure

wait(5)

local mouse = game:GetService("Mouse")

local nothingButton = script.Parent

local npcDialogueFrame = script.Parent.Parent

nothingButton.MouseButton1Up:Connect(function()

npcDialogueFrame.Visible = false

end)

Your 2nd script is a Localscript, this means that the frame is closed only for the player and not the server. You could use a RemoteEvent to switch the Localscript to a server script. Which would look something like this:

wait(5)

local mouse = game:GetService("Mouse")

local nothingButton = script.Parent

local npcDialogueFrame = script.Parent.Parent

nothingButton.MouseButton1Up:Connect(function()

	[location of the remoteevent]:FireServer(npcDialogueFrame)

end)

Then have another script in ServerScriptService which does this:

[Location of remoteevent].OnServerEvent:Connect(function(plr, gui)
	gui.Visible = false
end)

I hope this helps, if you want me to explain more about why it doesn’t work then just ask.
=)