Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I debounce this sliding door?

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!

2 comments

0

ClickDetectors have an event called MouseClick, not touched.

0

I know, I was too lazy to change it

1 answer

✓ Accepted answer

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.