I have quite a large sum of lightbulbs (spheres grouped together) that I would like to repeatedly Tween to a different colour and back simultaneously. I discovered that Tweening alone would not work, for the lightbulbs merely changed colour one at a time, as opposed to all at once. Therefore, I tried coroutining. With the script I’m currently using, however, none of the lightbulbs change whatsoever, and the output does not give any clue as to where I’ve gone wrong. If anyone could point out the error(s) in my script, it would be very much appreciated.
local Model = workspace.Colourful.Lightbulbs local TweenService = game:GetService("TweenService") local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0) local Goal1 = {Color = Color3.fromRGB(100, 100, 100)} local Goal2 = {Color = Color3.fromRGB(255, 195, 155)} while true do wait() coroutine.resume(coroutine.create(function() for i, part in pairs(Model:GetChildren()) do if part:IsA("BasePart") then local tween1 = TweenService:Create(part, tweenInfo, Goal1) tween1:Play() tween1.Completed:Wait(1) local tween2 = TweenService:Create(part, tweenInfo, Goal2) tween2:Play() tween2.Completed:Wait(1) end end end)) coroutine.yield() end
TweenInfo contains properties which allows you to repeat and reverse the tween. See if this works:
local TweenService = game:GetService('TweenService') local Model = workspace.Colourful.Lightbulbs for _, v in pairs(Model:GetChildren()) do if v:IsA('BasePart') then TweenService:Create(v, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true), {Color = Color3.fromRGB(100, 100, 100)}):Play() end end