Basically, im trying to make a door, and I made a script that works with only one button, however, I wanted to add a debounce so it can't be spammed. Only when I added it, it screwed up my script.
01 | if DoorDebounce = = false then |
02 | DoorDebounce = true |
03 | if DoorIsUp then |
04 | Door.Anchored = false |
05 | DownTween:Play() |
06 | print ( "tween just played" ) |
07 | wait( 5 ) |
08 | Door.Anchored = true |
09 | DoorIsUp = false |
10 | else |
11 | Door.Anchored = false |
12 | UpTween:Play() |
13 | print ( "tweenJustplayed" ) |
14 | wait( 5 ) |
15 | Door.Anchored = true |
Ya see, when I have the waits in there (like the code above) then the debounce works just fine, however this intern screws up the door when it's coming down. The opposite is true, when they are not there the debounce does not work, but the door does. I'm not sure how a wait can affect it. And yes, I have tested and I am positive that the "wait" is the problem.
wait()
is not the problem, however it shows you what is. You are unanchoring the doors during the tween. Tweens should be only played on anchored parts, otherwise Roblox physics interrupt them. Without wait()
your doors will quickly anchor back when the tween starts, and remain anchored for practically whole tween (starting a tween does not stop the script). When you add wait(5)
, your doors remain unanchored during the tween, thus preventing proper function.
Keep the doors anchored all the time (tweens like anchored parts), unless you specifically require them unachored for some situations. In this case at least anchor them for the duration of the tween.
01 | if DoorDebounce = = false then |
02 | DoorDebounce = true |
03 | if DoorIsUp then |
04 | DownTween:Play() |
05 | print ( "tween just played" ) |
06 | DownTween.Completed:Wait() --beter than wait(5) and more accurate |
07 | DoorIsUp = false |
08 | else |
09 | UpTween:Play() |
10 | print ( "tweenJustplayed" ) |
11 | UpTween.Completed:Wait() --beter than wait(5) and more accurate |
12 | DoorIsUp = true |
13 | end |
14 | DoorDebounce = false |
15 | end |
16 |
17 | end ) |
I hope this helps.