How to store Tweens in variables?

Because the Tweens I’m using right now get played frequently, I tried saving them in a table and looking it up when its time to play them. The first time the Tweens worked, but when the second time came around which is like a couple seconds, the Tweens didn’t play.

Are Tweens not able to be stored for a long time? If not, how can I make sure so that they can be saved and not have to be constantly created?

Thanks.

Edit: I printed the table at around the time the Tweens stop playing, it’s not empty.
@Inconcludable

-- Here's a sample code I created, for your information
-- this may not be accurate since it wasn't tested,
-- but you get the general idea..
local SavedTweens = {}

--[[
	A folder that contains 4 Timers is created
	the timers count down from 300 to 0
	everytime a timer inside the folder reaches 0
	
	a tween which is saved into a table is fired.
	Each Timer has their own Tween.
]]


local function InitTimeFolders()
	local TweenService = game:GetService("TweenService")
	local TimerFolder = Instance.new("Folder", workspace)
	
	local function CreateTimers()
		for i = 1, 4, 1 do
			local NewTimer =  Instance.new("NumberValue")
			TimerFolder[i] = NewTimer
			SavedTweens[NewTimer] = TweenService:Create(...) -- you get the point.
		end
	end
	
	local function CountdownToZero() -- i'm not writing this down..
	end
	
	
	local function FireTweenWhenZero(Timer, sec)
		if (sec <= 0) then
			local TweenTofire = SavedTweens[Timer] -- lookup on tween
			TweenTofire:Play()
		end
	end
	
	
	local function OnTimerChanged()
		for _,Timer in ipairs(TimerFolder) do
			Timer.Changed:Connect(function(sec)
				FireTweenWhenZero(sec)
			end)
		end
	end
	
	CreateTimers()
	CountdownToZero()
	OnTimerChanged()
end
1 Like

Just do

local Tween = tweenservice:Create(arguments here)
Tween:Play()
wait(2)
Tween:Cancel()
1 Like

Can you show your script? That’d help a lot

2 Likes