Color Rotation Stopping

yes, this will probably be the messiest code you’ve ever viewed.
essentially, this script cycles through rotating colors. it goes from blue to green, green to red, and so on.

-- Services

local TweenService = game:GetService("TweenService")

-- Tween Goals

local BlueGoal = {Color = Color3.fromRGB(0, 0, 255)}
local GreenGoal = {Color = Color3.fromRGB(0, 255, 0)}
local RedGoal = {Color = Color3.fromRGB(255, 0, 0)}
local OrangeGoal = {Color = Color3.fromRGB(232, 77, 0)}
local YellowGoal = {Color = Color3.fromRGB(255, 255, 0)}
local PinkGoal = {Color = Color3.fromRGB(255, 102, 204)}
local PurpleGoal = {Color = Color3.fromRGB(98, 37, 209)}

-- Functions

local TweenInfo1 = TweenInfo.new(
	1,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

local TweenInfo2 = TweenInfo.new(
	0.05,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

for i, Light in pairs(script.Parent:WaitForChild("Lights"):GetChildren()) do
	local PointLight = Instance.new("PointLight")
	PointLight.Brightness = 10
	PointLight.Range = 1
	PointLight.Color = Light.Color
	PointLight.Parent = Light
end

local Lights = script.Parent:WaitForChild("Lights"):GetChildren()

local function TweenLights()
	for i, Light in pairs(Lights) do
		-- Light is Blue. (Turn Green)
		if Light.Color == Color3.fromRGB(0, 0, 255) then
			print("Light is Blue. (Turn Green)")
			local GreenTween = TweenService:Create(Light, TweenInfo1, GreenGoal)
			GreenTween:Play()
			-- Light is Green. (Turn Red)
		elseif Light.Color == Color3.fromRGB(0, 255, 0) then
			print("Light is Green. (Turn Red)")
			local RedTween = TweenService:Create(Light, TweenInfo1, RedGoal)
			RedTween:Play()
			-- Light is Red. (Turn Orange)
		elseif Light.Color == Color3.fromRGB(255, 0, 0) then
			print("Light is Red. (Turn Orange)")
			local OrangeTween = TweenService:Create(Light, TweenInfo1, OrangeGoal)
			OrangeTween:Play()
			-- Light is Orange. (Turn Yellow)
		elseif Light.Color == Color3.fromRGB(232, 77, 0) then
			print("Light is Orange. (Turn Yellow)")
			local YellowTween = TweenService:Create(Light, TweenInfo1, YellowGoal)
			YellowTween:Play()
			-- Light is Yellow. (Turn Pink)
		elseif Light.Color == Color3.fromRGB(255, 255, 0) then
			print("Light is Yellow. (Turn Pink)")
			local PinkTween = TweenService:Create(Light, TweenInfo1, PinkGoal)
			PinkTween:Play()
			-- Light is Pink. (Turn Purple)
		elseif Light.Color == Color3.fromRGB(255, 102, 204) then
			print("Light is Pink. (Turn Purple)")
			local PurpleTween = TweenService:Create(Light, TweenInfo1, PurpleGoal)
			PurpleTween:Play()
			-- Light is Purple. (Restart and Turn Blue.)
		elseif Light.Color == Color3.fromRGB(98, 37, 209) then
			print("Light is Purple. (Restart and Turn Blue.)")
			local BlueTween = TweenService:Create(Light, TweenInfo1, BlueGoal)
			BlueTween:Play()
		end
	end
end

local Coroutine1 = coroutine.create(function()
	while true do
		TweenLights()
		task.wait(2.5)
		print("Colors restarted.")
	end
end)

local Coroutine2 = coroutine.create(function()
	while true do
		for i, Light in pairs(Lights) do
			local Color = Light.Color or Light.Changed:Wait()
			local PointLight = Light:WaitForChild("PointLight")
			local TweenGoal = {Color = Light.Color}
			local Tween = TweenService:Create(PointLight, TweenInfo2, TweenGoal)
			Tween:Play()
		end
		task.wait()
	end
end)

coroutine.resume(Coroutine1)
coroutine.resume(Coroutine2)

my only issue is that there are two bulbs that get stuck on purple and don’t change back to blue. the rest keep changing until they reach pink and never change to purple.
help is appreciated.

changed the script entirely into a seperate modulescript.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.