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!
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!