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

Why won't this debounce work?

Asked by 9 years ago

This debounce doesn't work and I tried everything to fix it and it still doesn't work. PLEASE HELP!!!

local door = script.Parent.Parent.Door


pressed = false
function onClicked()
    if not pressed then
        pressed = true
        wait()
        for i = .25, 4 do
            door.CFrame = door.CFrame * CFrame.new(0, i, 0)
            wait(.05)
            print("yas")
        end
        door.Transparency = 1
        pressed = false
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 answer

Log in to vote
0
Answered by 9 years ago

In the future, you should consider giving at least a short summary of what exactly is not working in your script so that you can be better assisted. Anyway...

I modified your for statement just tad because it seemed a bit 'iffy' to me. I also cleaned up your code every so slightly and adjusted the 'opening' or the door. I don't see anything wrong with the debounce, so perhaps there is another issue that is plaguing you if this new version does not work.

local door = script.Parent.Parent.Door

pressed = false
function onClicked()
    if pressed then return end
    pressed = true
    wait()
    for i = .25, 4, .05 do
        door.CFrame = door.CFrame * CFrame.new(0, i, 0)
        wait(0.01)
    end
    door.Transparency = 1
    pressed = false
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)
Ad

Answer this question