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.
01 | local tweenService = game:GetService( "TweenService" ) |
02 | local clickDetector = script.Parent.Parent.Trigger |
03 | local seconds = 4.6 |
04 | debounce = true |
05 |
06 |
07 | clickDetector.Touched:Connect( function () |
08 | if debounce = = true then |
09 | debounce = false |
10 | end |
11 | script.Parent.Sound:Play() |
12 | tweenService:Create(script.Parent, TweenInfo.new(seconds, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), { CFrame = CFrame.new( 216.762 , 40.341 , - 192.229 ) } ):Play() |
13 | wait( 6.6 ) |
14 | script.Parent.Sound:Play() |
15 | tweenService:Create(script.Parent, TweenInfo.new(seconds, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), { CFrame = CFrame.new( 216.762 , 31.888 , - 192.229 ) } ):Play() |
16 | debounce = true |
17 | end ) |
Thank you if you can help me!
Heres the code!
01 | local tweenService = game:GetService( "TweenService" ) |
02 | local clickDetector = script.Parent.Parent.Trigger |
03 | local seconds = 4.6 |
04 | debounce = false -- Set this to false. |
05 |
06 |
07 | clickDetector.Touched:Connect( function () |
08 | if debounce = = false then -- Check if its false, this means its not running. |
09 | debounce = true -- Set it to true, this means its running! |
10 | script.Parent.Sound:Play() |
11 | tweenService:Create(script.Parent, TweenInfo.new(seconds, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), { CFrame = CFrame.new( 216.762 , 40.341 , - 192.229 ) } ):Play() |
12 | wait( 6.6 ) |
13 | script.Parent.Sound:Play() |
14 | tweenService:Create(script.Parent, TweenInfo.new(seconds, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), { CFrame = CFrame.new( 216.762 , 31.888 , - 192.229 ) } ):Play() |
15 | debounce = false -- Set it to false, this means its not running! |
16 | end |
17 | 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!