Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How Can I Add Cooldown/Debounce To My Script ?

Asked by
Split_s 21
2 years ago
Edited 2 years ago

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

Log in to vote
0
Answered by 2 years ago
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)
Ad

Answer this question