Tween multiple Parts to a New Color and back ( SOLVED / MULTIPLE SOLUTIONS)

Hello, i want to turn the Bulbs in this Theater to black with Tweenservice. They are all in a Model and just one Part. I need some help Remembering again how to do this.

Script:

local clickdetector = script.Parent.ClickDetector

TweenService = game:GetService("TweenService")

info = TweenInfo.new(7,Enum.EasingStyle.Linear)

local S1		= game.Workspace.AudiBulbs:getChildren()




	
	script.Parent.ClickDetector.MouseClick:Connect(function()
		local goal = {}
	goal.Color = Color3.fromRGB(0, 0, 0)

	local tween1 = TweenService:Create(S1,info,goal)

	
	tween1:Play()

end)

I want to adress all the Parts in the Model to be tweened. I know i did it before but i totally forgot how i did it and cant find the Script anymore on how.
I miss a Step for sure. Any help is appricated =)

Put all the lights into a Table, then pull them from that with ipairs.

It’s because the first argument you provided in the tween is a table, it needs to be an object/instance. Thus,you can loop through all the lights, and then provide its index.

Try this,

local clickdetector = script.Parent.ClickDetector
TweenService = game:GetService("TweenService")
info = TweenInfo.new(7,Enum.EasingStyle.Linear)
local S1= game.Workspace.AudiBulbs:getChildren()

script.Parent.ClickDetector.MouseClick:Connect(function()
    local goal = {}
	goal.Color = Color3.fromRGB(0, 0, 0)

    for  k = 1,#S1 do
        local tween1 = TweenService:Create(S1[k],info,goal)
        tween1:Play()
    end
end)

Use for loops

local clickdetector = script.Parent.ClickDetector
local TweenService = game:GetService("TweenService")
info = TweenInfo.new(7,Enum.EasingStyle.Linear)
local S1 = game.Workspace.AudiBulbs:GetChildren() -- GetChildren returns a table of all the instances.

script.Parent.ClickDetector.MouseClick:Connect(function()
	local goal = {}
	goal.Color = Color3.fromRGB(0, 0, 0)
	for i,part in pairs(S1) do -- Gets each part from the table
		local tween1 = TweenService:Create(part,info,goal)
		tween1:Play()
	end
end)

Thanks guys that all worked. I just had a big Brain Fart with this =D

Thanks again!

1 Like

Please mark the post that helped you as a solution so it will help the others to find the solution
and it will make other developers sure that this post have a solution.

1 Like

Thats why i say it all worked. Its up to someone else what works for them :slight_smile:
Thanks again

But what will happen is that someone looking for an answer will see it as unsolved so they may not read it.

Or someone else looking for unsolved posts will read it trying to solve it and will be wasting their time when they could be solving some other post.

Please mark whichever post solved your issue as the Solution to benefit everyone involved.

1 Like