Hi so i’m looking to use :Pause() for a tween that’s located in ANOTHER script, in a localscript but I don’t know how to find tweens or where they are located. How would I be able to find this tween so I can stop it from running in another script that’s separate? Thank you.
You could create a module script for this or use BindableEvents. You can fire the bindable and have the other script detect it and cancel the tween. If you use a module script, you can create a function that cancels it.
If it’s Server → Client (or vice versa) use RemoteEvents. (usage)
Tweens aren’t Instances in the same way that "Part"s are. I’m wrong, but still don’t recommend parenting them places
They’re closer to tables or strings or numbers—just variables, not parented anywhere and have no concept of “where”.
Then how am I supposed to find them and cancel it? I can only do that in the script that it was created in?
Yup!
That, or you expose it to the outside world somehow.
Like @HugeCoolboy2007 said, you can use events to do that.
Or you could wrap your tweens in a ModuleScript that lets two scripts access the same tween (that works because module scripts are sort of the same script as the one require
’ing them).
No, they are instances – the same way BaseParts are. TweenService:Create()
returns a Tween
instance which, of course, inherits the same properties from the base Instance class
In the same way as other instances, I can parent it somewhere.
local tw = game:GetService("TweenService"):Create(workspace.Baseplate, TweenInfo.new(1), {Size = Vector3.new(50, 20, 50)})
tw.Parent = workspace
And there’s your object
Dang, fair play
I still don’t think it’s a good idea to parent them somewhere just to expose their methods to multiple scripts, but hey, if it’s possible and it works, I’m not a cop.
Also you have a memory leak if you don’t destroy your tweens!
Are both of your scripts LocalScript?
If so, try using “_G” to reference the tween in another script.