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

How can I get the sound to debounce here?

Asked by
Azuc 112
6 years ago

Basically, if the door is locked it plays a sound

DoorO.Object.No:Play()

which is located at the end of a if statement checking to see if the doors locked value is set to true, however this leaves players the ability to spam the handle and make the lock sound over and over with no delay.

I've tried a few different ways start with more if statements and ending with just adding a value called knocked and having it check if thats set to true before playing the sound but still it made no change.

Not sure what I am doing wrong here.

local Locked = script.Parent.Parent.Parent.Locked
local DoorC = script.Parent.Parent.Parent.Close
local DoorO = script.Parent.Parent.Parent.Open
local CC1 = DoorC.lock1.ClickDetector
local CC3 = DoorC.hand1.ClickDetector
local CC4 = DoorC.hand2.ClickDetector
local OC3 = DoorO.hand1.ClickDetector
local OC4 = DoorO.hand2.ClickDetector

script.Parent.ClickDetector.mouseClick:connect(function(Player)
    if Locked.Value == false then
        for i,v in pairs(DoorC:GetChildren()) do
        if(v.className == "Part")then 
        v.Transparency = 0
        v.CanCollide = true
            end
        end
        for i,v in pairs(DoorC:GetChildren()) do
        if(v.className == "MeshPart")then 
        v.CanCollide = false
            end
        end
        for i,v in pairs(DoorO:GetChildren()) do
        if(v.className == "Part")then 
        v.Transparency = 1
        v.CanCollide = false
            end
        end
        OC3.MaxActivationDistance = 0
        OC4.MaxActivationDistance = 0
        CC1.MaxActivationDistance = 20
        CC3.MaxActivationDistance = 20
        CC4.MaxActivationDistance = 20
        DoorO.Object.Open:Play()
    else
        DoorO.Object.No:Play()
    end
end)

1 answer

Log in to vote
1
Answered by
Optikk 499 Donator Moderation Voter
6 years ago

Wrap the entire "if" statement you have within another if statement. Example:

local Debounce = false

ClickDetector.MouseClick:Connect(function()
    if Debounce == false then
        Debounce = true
        Sound:Play()
        wait(2)
        Debounce = false
    end
end)
Ad

Answer this question