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

How do I add debounce to this short script? [closed]

Asked by 5 years ago

Hey I was wondering how I'd add a debounce tot his short script, any help would be appreicated. :)

function onTouched(part)
    script.Parent.Parent.DoorScript.open.Value = true
    wait(3)
    script.Parent.Parent.DoorScript.open.Value = false
end


script.Parent.Touched:connect(onTouched)

Closed as Not Constructive by hiimgoodpack, Le_Teapots, noammao, Psudar, zblox164, SuperSamyGamer, SirDerpyHerp, and Lugical

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

2 answers

Log in to vote
1
Answered by 5 years ago
canopen = true -- the db

function onTouched(part)
    if canopen then
        canopen = false
        script.Parent.Parent.DoorScript.open.Value = true
        wait(2)
        script.Parent.Parent.DoorScript.open.Value = false
        canopen = true
    else
        print("Cannot open.")
    end
end


script.Parent.Touched:connect(onTouched)

Hope that helped. :)

0
It just makes the time the door is closed for longer? LouieN07 16 — 5y
0
as I changed the wait time LouieN07 16 — 5y
0
wait just changes the time you need to wait before you can open again develop_d 53 — 5y
0
this script works, I don't know why it was unmarked as the answer Le_Teapots 913 — 5y
Ad
Log in to vote
0
Answered by
noammao 294 Moderation Voter
5 years ago
local debounce = false

function onTouched(part)
if debounce = false then
    debounce = true
    script.Parent.Parent.DoorScript.open.Value = true
    wait(3)
    script.Parent.Parent.DoorScript.open.Value = false
    debounce = false
    end
end


script.Parent.Touched:connect(onTouched)