Is it possible to make one tween for multiple parts while still being able to cancel the tweens efficiently

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a tween for multiple parts inside of a model for a layer of a tower. The selected layer will indicate it’s selected by flashing.
  2. What is the issue? Include screenshots / videos if possible!
    I can’t turn the tween off for the different tower layers.

What I want it to look like: (with tween)


What it currently looks like:

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried making a function to make the selected layer flash. I added a for loop to the flash function, but I can’t refer to a tween inside of the for loop.
local layerNumber = 1 --this is the layerNumber
local layerAmt = workspace.Tower3:GetChildren()

--tween
local info = TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,-1,true)
local goal = {Color = Color3.new(1)}
local tween = ts:Create("parts",info,goal)
------------------------------

local function GetLayerFromNumber(layerN) --layer Names are numbered 
	local layer = game.workspace.Tower3[layerN]
	return layer
end

local function flashStory(layer)

	
	--what I had
	for i,v in ipairs(layerAmt) do
		local tween = ts:Create(v,info,goal)
		tween:play()
	end
	------------------------------
end

flashStory(GetLayerFromNumber(layerNumber))

upButton.MouseButton1Click:Connect(function() --gui to cycle to the above layer
	layerNumber = layerNumber+1
	flashStory(GetLayerFromNumber(layerNumber))
end)

This is my first post, sorry for any inconvenience!

Remove the script and go to the parts you want and change it to:

163,162,165

The top one is:

255,255,255

Thanks for the response, is there any way I can make the layer tween to that color while reverting the other layer back to it’s original color?

You would need to create 2 separate variables for the top layer and bottom layer. You could make a folder/model inside of the Tower3 and name them “TopLayer” and “BottomLayer”

local layerNumber = 1 --this is the layerNumber
local btmlayer = workspace.Tower3.BottomLayer:GetChildren()
local toplayer = workspace.Tower3.TopLayer:GetChildren()

local btmcolor = Color3.fromRGB(255,0,0)
local topcolor = Color3.fromRGB(255,255,255)

--tween
local info = TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,-1,true)
local goal = {Color = Color3.new(1)}
local tween = ts:Create("parts",info,goal)
------------------------------

local function GetLayerFromNumber(layerN) --layer Names are numbered 
	local layer = game.workspace.Tower3[layerN]
	return layer
end

local function flashStory(layer)

	for i,v in ipairs(btmlayer) do
		if btmcolor == Color3.fromRGB(255,255,255) then
			btmcolor = Color3.fromRGB(255,0,0)
			local tween = ts:Create(v,info,{Color = btmcolor})
			tween:play()
		else
			btmcolor = Color3.fromRGB(255,255,255)
			local tween = ts:Create(v,info,{Color = btmcolor})
			tween:play()
		end
	end

	for i,v in ipairs(toplayer) do
		if topcolor == Color3.fromRGB(255,255,255) then
			topcolor = Color3.fromRGB(255,0,0)
			local tween = ts:Create(v,info,{Color = topcolor})
			tween:play()
		else
			topcolor = Color3.fromRGB(255,255,255)
			local tween = ts:Create(v,info,{Color = topcolor})
			tween:play()
		end
	end

	--------------
end

flashStory(GetLayerFromNumber(layerNumber))

upButton.MouseButton1Click:Connect(function() --gui to cycle to the above layer
	layerNumber = layerNumber+1
	flashStory(GetLayerFromNumber(layerNumber))
end)

This is working, but half of the parts are red and the other half are white

isn’t that what you wanted? I looked at the picture you provided that you wanted, so I’m confused as to why you say that it’s a problem?

Sorry, I am not being clear. I mean that half of the parts in one of the layers is not working. so 1/4 of the entire tower is not functioning correctly.

this is what it looks like:


sometimes it will be the walls on the left and right

here is my model in the explorer:
image

Ohh, thats my fault. I didn’t do the script completely right, so here’s the fixed version:

local layerNumber = 1 --this is the layerNumber
local btmlayer = workspace.Tower3.BottomLayer:GetChildren()
local toplayer = workspace.Tower3.TopLayer:GetChildren()

local btmcolor = Color3.fromRGB(255,0,0)
local topcolor = Color3.fromRGB(255,255,255)

--tween
local info = TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,-1,true)
local goal = {Color = Color3.new(1)}
local tween = ts:Create("parts",info,goal)
------------------------------

local function GetLayerFromNumber(layerN) --layer Names are numbered 
	local layer = game.workspace.Tower3[layerN]
	return layer
end

local function flashStory(layer)

	for i,v in ipairs(btmlayer) do
		local tween = ts:Create(v,info,{Color = btmcolor})
		tween:play()
	end

	if btmcolor == Color3.fromRGB(255,255,255) then
		btmcolor = Color3.fromRGB(255,0,0)
	else
		btmcolor =Color3.fromRGB(255,255,255)
	end

	for i,v in ipairs(toplayer) do
		local tween = ts:Create(v,info,{Color = topcolor})
		tween:play()
	end

	if topcolor == Color3.fromRGB(255,255,255) then
		topcolor = Color3.fromRGB(255,0,0)
	else
		topcolor =Color3.fromRGB(255,255,255)
	end
	--------------
end

flashStory(GetLayerFromNumber(layerNumber))

upButton.MouseButton1Click:Connect(function() --gui to cycle to the above layer
	layerNumber = layerNumber+1
	flashStory(GetLayerFromNumber(layerNumber))
end)

Also sorry for late response, I’m cleaning my jacuzzi rn

1 Like

This works great. Do you know of any way I can stop the flashing to indicate that I have switched the selected layer?

You can create a table for the tweens and use tween:Stop() to stop them.

I am familiar with tables, but how would a tween go into a table?

Use table.insert for it. table.insert(table, tween)

1 Like

And then I would just do table[1]:Stop?

No, you would iterate over the table with a for loop ex:

for i,v in pairs(table) do
    v:Cancel()
end
1 Like

That is the solution with a minor mistake. After some research, I found that it’s tween:Cancel() and not tween:Stop(). If you fix that I will mark your response as solution

Thank you for your time and patience! :grinning:

Ah, I don’t work with tweens much and thought it was Stop(), but glad I could help!

1 Like