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.
if DoorDebounce == false then DoorDebounce = true if DoorIsUp then Door.Anchored = false DownTween:Play() print("tween just played") wait(5) Door.Anchored = true DoorIsUp = false else Door.Anchored = false UpTween:Play() print("tweenJustplayed") wait(5) Door.Anchored = true DoorIsUp = true end DoorDebounce = false end end)
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.
if DoorDebounce == false then DoorDebounce = true if DoorIsUp then DownTween:Play() print("tween just played") DownTween.Completed:Wait() --beter than wait(5) and more accurate DoorIsUp = false else UpTween:Play() print("tweenJustplayed") UpTween.Completed:Wait() --beter than wait(5) and more accurate DoorIsUp = true end DoorDebounce = false end end)
I hope this helps.