Edit 11/28/2021: Updated thread to include StopAll() information.
Edit 01/14/2022: Realized I forgot the API documentation, working on it now
Edit 04/16/2022: Wheeee, I still haven’t had time to work on an API doc. I gotta cut down on the number of projects I’m doing. Somebody send help.
Hello TweenService enthusiasts! (Or anti-TweenService enthusiasts.) As some of you may know, Tweens are a great way to smoothly animate properties of any Instance within Roblox experiences, to give a “high quality” appearance at a significantly reduced performance cost when compared to while true do
, while wait() do
, and for i=420,69,-1 do
loops.
However, what not every TweenService user knows is that Tweens do not clean up after themselves when playing. Therefore, creating Tweens that will only be used once can eventually build up useless space on the server, causing cascading lag as the server runs for longer periods of time. This can be easily fixed with a simple code snippet that destroys the Tween upon being completed; I’ll leave it to the Community Tutorials tab to show you how to do this, though.
Typing this call over and over can be quite time-consuming though, so I made a module specifically to save developers many a keystroke and allow Tweens to be used and automatically cleaned up in any script–even LocalScripts if you put the module in ReplicatedStorage!–known simply as “Smart Tween”.
The module has three functions, those being “Tween”, “TweenModel”, and “StopAll”. An API documentation is included within the module so that you can understand what both of these even do. If you’re confused, please contact me with your questions! I’m pretty sure that people have made this module for their own games many times before, but if not, I’ll consider that quite the surprise.
Here’s the module link on the Library!
https://www.roblox.com/library/7925918452/Smart-Tween
Hope this helps you protect your wrists while developing that new banger of a game–I mean, “experience” that you’re working on! All I ask is that you credit me if you use this. I eventually plan to add features to tween ColorSequence
and NumberRange
objects, though that’ll come at a later time when I can work on this module more actively.
Anyway, cheers!
– Catz.
NOTE: TWEENMODEL() ONLY WORKS ON MODELS WITH A PRIMARY PART, AND ONLY WORKS ON CFRAME AT THE MOMENT
Edit: Darn typos.