How to delete Event:Wait()

I want to make sure there is 0 chances of Event:wait() causing memory leaks, especially when there’s gonna be like a good 2000 things spawning. Can I destroy an Event:Wait() or will deleting scripts work?

I wouldn’t connect a wait to the event. instead just connect a function that can monitor whats going on.

Well, yeah, but I need to run it inside a for loop to softcode it, and also it’s just tweening. I’m not sure about if Tweening.Complete:Wait() will cause memory leaks

Unfortunately you can’t, only way to prevent this from happening is to check if whatever was supposed to fire the event happened before doing Event:Wait(). Unless what you want to do is stop the yielding event after some time or due to some other event, that’s another thing.

1 Like

Ok. What’s the thresh hold of Tween.Completed:Wait() without it starting to look choppy?

What do you mean by starting to look choppy? (also it seems like there is a :Cancel() that stops a tween, and also stops the :Wait() connection, along with a seperate coroutine to constantly check)

@minimic2002 although it would surely cause some lag, physics aren’t the reason for that. For example, if you tweened something and that something touched a part with a .Touched connection, it won’t actually fire .Touched. Tweening doesn’t work with physics.

2 Likes

If you are using tween on 2000 parts. Its going to get choppy. Any mass movement of parts means roblox has to add it to the physics.

(I hope you arent tweening 2000 parts lol)

1 Like

Any anchored part that is moved wont fire.Touched events, however if the part bumps into it, it still will fire. The same goes for setting parts CFrame and position.

Tweens can be touched. But if they are the one moving then no, the event wont fire.

I have however found a work around for this. You can make something appear solid / noncollide and use .touched. You can basically quickly turn collision on then off (or off then on) and this will fire the .touched without any difference being realised. so if its non collide you could walk right through it and it could flip on and off and you wouldnt even know.

1 Like

How do I add a :Cancel() to a for loop of tweens?

Of course it depends on your code. Pretty much before the Tween.Complete:Wait(), you setup a coroutine, and inside it, I assume you play the tweens, and at the same time set up the while loop which constantly checks if the Tween.Complete:Wait() should be stopped by :Cancel()ing.