-
What do you want to achieve? Keep it simple and clear!
I want to add tweens to a table so that I can then play them at the same time. These tweens do not play on the same parts. I want to do this because I want to press a gui button that plays the two tweens on two different groups of parts that I grouped with a tag property. -
What is the issue? Include screenshots / videos if possible!
The issue is that when I add the tweens to the table, only the second tween plays. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
What I have tried is to remove the [1] from tweens[1]:Play and only do tweens:Play() but that does not play either tween and I get the error “attempt to call missing method ‘Play’ of table.”
I do want to add that if i add a wait between the two tweens as I add them to the table, it works! But I don’t want to have a big wait between the tweens running. I want them to play at the same time.
Here is the original script and video of how it looks.
local TweenService = game:GetService("TweenService")
local CollectionService = game:GetService("CollectionService")
local Module = require(script.ModuleScript)
local Button = Module.Buttons
local Bulbs = Module.Bulbs
local LEDs = Module.LEDs
local TweenInfo = Module.Tween
local Color = Module.Colors
local tweens = {}
local tweensRunning = false
function runTween()
tweensRunning = true
tweens[1]:Play()
warn("TWEEN SUCCESSFUL")
table.remove(tweens, 1)
if #tweens > 0 then
runTween()
else
tweensRunning = false
end
end
function addTween(tweenToAdd)
table.insert(tweens, tweenToAdd)
if not tweensRunning then
task.spawn(runTween)
end
end
local function BulbTweens(tagIndex, initialColorValue, finalColorValue)
for _, Lights in pairs(CollectionService:GetTagged(Bulbs[tagIndex])) do
local initialColor = TweenService:Create(Lights, TweenInfo[1], initialColorValue)
local finalColor = TweenService:Create(Lights, TweenInfo[2], finalColorValue)
Button[1].MouseButton1Click:Connect(function()
addTween(initialColor)
print("INITIAL TWEEN IN TABLE")
addTween(finalColor)
print("FINAL TWEEN IN TABLE")
end)
end
end
BulbTweens(1, Color[21], Color[25])
BulbTweens(2, Color[25], Color[21])
Now here I will use the same script except I add a wait(5) at line 39 between addTween(initialColor) and addTween(finalColor)
So I know a solution, I just want to know if there is a better one or if there is a different way to achieve the same result differently? Any suggestions are welcome, thank you!