How do I make a cooldown for a command prompt dialog box?

I am fairly new to scripting and I want to know how to make a cooldown to a dialog system I’m making

local proximityprompt = game.Workspace.Dialog.Chillems.ProximityPrompt
local sfx = script.Parent.clicksound

proximityprompt.Triggered:Connect(function()
		script.Parent.Visible = true
		script.Parent.Frame.Text1.Visible = true
	sfx:Play()
		wait(2)
		script.Parent.Frame.Text1.Visible = false
		script.Parent.Frame.Text2.Visible = true
	sfx:Play()
		wait(1)
		script.Parent.Frame.Text2.Visible = false
		script.Parent.Visible = false
	sfx:Play()
end)

You would add a debounce. How long do you want the cool down to last, and it should happen after a player interacts with your dialog prompt correct?

1 Like

Try this

local proximityprompt = game.Workspace.Dialog.Chillems.ProximityPrompt
local sfx = script.Parent.clicksound
local debounce = false
local waitTime = 1
proximityprompt.Triggered:Connect(function()
	if debounce == false then
		debounce = true
		script.Parent.Visible = true
		script.Parent.Frame.Text1.Visible = true
		sfx:Play()
		wait(2)
		script.Parent.Frame.Text1.Visible = false
		script.Parent.Frame.Text2.Visible = true
		sfx:Play()
		wait(1)
		script.Parent.Frame.Text2.Visible = false
		script.Parent.Visible = false
		sfx:Play()
		sfx.Ended:Wait()
		debounce = false
	end
end)
1 Like

the text dont overlap each other anymore, thank you!

1 Like

@VeriBaesix helped me on that, I’ll keep debounce in mind the next time I’m working on something