Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How Can I Add Cooldown/Debounce To My Script ?

Hello ! So Im Trying To Add A Cooldown By Using Debounce But I Dont Know How . I Want To Add A Cooldown For When I Open And Close The Curtains , Can Someone Help Me ?

V Script V

local ProximityPrompt = script.Parent.Interact.ProximityPrompt
local CurtainL = script.Parent.CurtainL
local CurtainR = script.Parent.CurtainR
local ClosedCurtainL = script.Parent.ClosedCurtainL
local ClosedCurtainR = script.Parent.ClosedCurtainR

ProximityPrompt.Triggered:Connect(function()
	if ProximityPrompt.ActionText == "Open" then --the text is set to "Open"
		script.Parent.Sound:Play()
		CurtainL.Transparency = 0
		CurtainR.Transparency = 0 -- the brightness off
		ClosedCurtainL.Transparency = 1
		ClosedCurtainR.Transparency = 1
		ProximityPrompt.ActionText = "Close" --text change to "Close"
	else
		script.Parent.Sound:Play()
		CurtainL.Transparency = 1-- the brightness on
		CurtainR.Transparency = 1
		ClosedCurtainL.Transparency = 0
		ClosedCurtainR.Transparency = 0
	    ProximityPrompt.ActionText = "Open" --text change to "Open"
	end
end)

1 answer

✓ Accepted answer
local ProximityPrompt = script.Parent.Interact.ProximityPrompt
local CurtainL = script.Parent.CurtainL
local CurtainR = script.Parent.CurtainR
local ClosedCurtainL = script.Parent.ClosedCurtainL
local ClosedCurtainR = script.Parent.ClosedCurtainR
local debounce = false

ProximityPrompt.Triggered:Connect(function()
	if debounce then return end
	debounce = true
    if ProximityPrompt.ActionText == "Open" then --the text is set to "Open"
        script.Parent.Sound:Play()
        CurtainL.Transparency = 0
        CurtainR.Transparency = 0 -- the brightness off
        ClosedCurtainL.Transparency = 1
        ClosedCurtainR.Transparency = 1
        ProximityPrompt.ActionText = "Close" --text change to "Close"
    else
        script.Parent.Sound:Play()
        CurtainL.Transparency = 1-- the brightness on
        CurtainR.Transparency = 1
        ClosedCurtainL.Transparency = 0
        ClosedCurtainR.Transparency = 0
        ProximityPrompt.ActionText = "Open" --text change to "Open"
    end
	wait(3) -- Change if needed
	debounce = false
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.