Pausing all tweens then unpausing

The title says it all, My goal is to find a way to pause tweens or freeze objects being tweened then unpause them after a certain duration.
If that’s too difficult to understand I’m trying to make a timestop which freezes everything.

Originally my idea was to simply anchor everything on the map but seeing as objects being tweened (a lot of my projectiles use tweening) can move while anchored that idea will no longer work.

A few ideas I have and wonder if they could be possible would be [disabling tween service temporarily, attaching scripts to anything thats tweening, simply a pause all tween command or plugin type thing, changing universal physics temporarily]

I would prefer to find a way which can operate from one script because going back into every single script with a tween to add something new would be a really big hassle.

Make a BoolValue in the affected parts via script, then pause the tweens if the BoolValue returns true, you understand?

1 Like

You can only start/pause a tween if you have the actual Tween object, so you absolutely have to store the Tween somewhere. There is no way to affect a Tween that you don’t have access to (other than by trampling over it with another Tween)

I suggest a ModuleScript to keep track of all currently running tweens.
Something like this: (I can’t test it, but I’m very confident that my little example scripts run on the first try)

local module = {}
local tweens = {} -- map of Tween = true where each tween is currently running

-- module.StartTween will run this in a new thread to prevent that :Wait() from yielding your script
local function StartTween(tween)
	tweens[tween] = true
	tween:Start()
	tween.Completed:Wait()
	tweens[tween] = nil
end

function module.StartTween(tween)
	return coroutine.wrap(StartTween)(tween)
end

function module.PauseTweens()
	-- for those confused: it's like a for k,v in pairs() loop, except we only care about k
	for tween in pairs(tweens) do
		tween:Pause()
	end
end

function module.ResumeTweens()
	for tween in pairs(tweens) do
		tween:Start()
	end
end

return module

You would have to replace every :Start() with that StartTween(tween) from this module.