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

How do I debounce this sliding door?

Asked by 6 years ago

I'm trying to make a sliding door that moves and plays a sound, but if you're in the trigger it'll play the sound repeatedly and the door closes slowly, and it's being very annoying.

local tweenService = game:GetService("TweenService")
local clickDetector = script.Parent.Parent.Trigger
local seconds = 4.6
debounce = true


clickDetector.Touched:Connect(function()
    if debounce == true then
        debounce = false
    end
    script.Parent.Sound:Play()
tweenService:Create(script.Parent, TweenInfo.new(seconds, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {CFrame = CFrame.new(216.762, 40.341, -192.229)}):Play()
wait(6.6)
script.Parent.Sound:Play()
tweenService:Create(script.Parent, TweenInfo.new(seconds, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {CFrame = CFrame.new(216.762, 31.888, -192.229)}):Play()
debounce = true
end)

Thank you if you can help me!

0
ClickDetectors have an event called MouseClick, not touched. User#19524 175 — 6y
0
I know, I was too lazy to change it CaptainAlien132 225 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

Heres the code!

local tweenService = game:GetService("TweenService")
local clickDetector = script.Parent.Parent.Trigger
local seconds = 4.6
debounce = false -- Set this to false.


clickDetector.Touched:Connect(function()
    if debounce == false then -- Check if its false,  this means its not running.
            debounce = true -- Set it to true, this means its running!
            script.Parent.Sound:Play()
        tweenService:Create(script.Parent, TweenInfo.new(seconds, Enum.EasingStyle.Quad,        Enum.EasingDirection.InOut), {CFrame = CFrame.new(216.762, 40.341, -192.229)}):Play()
        wait(6.6)
        script.Parent.Sound:Play()
        tweenService:Create(script.Parent, TweenInfo.new(seconds, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {CFrame = CFrame.new(216.762, 31.888, -192.229)}):Play()
        debounce = false -- Set it to false, this means its not running!
    end
end)

You just had your code a little messed up. If doubunce == false that means its not running if its true that means its running!

Ad

Answer this question