How would I make it so only a certain half of Models in a folder are active and the other half in-active

I just got the motivation to start working with PlaybackLoudness again and I’m trying to make it so that one half (Half1) is enabled and Half2 is disabled. The issue is that since Light 2 is in Half1 and not in Half2 it keeps saying its an invalid member, what could I do?

Code:

-- // Services \\ --
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")

-- // Variables \\ --
local Music = game.Workspace.Music
local StageLights = game.Workspace:WaitForChild("StageLights", 10)

-- // Main \\ --
while wait(0.05) do
	if Music.IsPlaying then
		if Music.PlaybackLoudness >= 400 then
			local waitDelay = 0.2 - (Music.PlaybackLoudness * 0.001)
			local randomOrientationY = math.random(-40, 40)
			local randomOrientationZ = math.random(30, 65)

			for i,lightModel in pairs(StageLights:GetChildren()) do  
				lightModel.PrimaryPart.CFrame = lightModel.PrimaryPart.CFrame 
					* CFrame.new(lightModel.PrimaryPart.Position, Vector3.new(
						lightModel.PrimaryPart.Position.X,
						lightModel.PrimaryPart.Position.Y + math.random(2, 3),
						lightModel.PrimaryPart.Position.Z + math.random(2, 4)
						)
					)
				lightModel.Light1.light.Enabled = true 
				lightModel.Light2.light.Enabled = false 
			end
			
			wait(waitDelay)
			for _,lightModel in pairs(StageLights:GetChildren()) do  
				lightModel.Light1.light.Enabled = false 
				lightModel.Light2.light.Enabled = true 

			end
		end
	end
end

Folder:
image

I’m not sure I understood correctly. Do you want all lights in all models half1 and half2 to take turns being active?

Side note: consider changing wait() to task.wait(), it’s a newer version of it. Also, consider using ipairs() instead of pairs() when using :GetChildren() etc, I believe it is a more efficient version.

Should fix with this:

-- // Services \\ --
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")

-- // Variables \\ --
local Music = game.Workspace.Music
local StageLights = game.Workspace:WaitForChild("StageLights", 10)

-- // Main \\ --
while wait(0.05) do
	if Music.IsPlaying then
		if Music.PlaybackLoudness >= 400 then
			local waitDelay = 0.2 - (Music.PlaybackLoudness * 0.001)
			local randomOrientationY = math.random(-40, 40)
			local randomOrientationZ = math.random(30, 65)

			for i,lightModel in pairs(StageLights:GetChildren()) do  
				lightModel.PrimaryPart.CFrame = lightModel.PrimaryPart.CFrame 
					* CFrame.new(lightModel.PrimaryPart.Position, Vector3.new(
						lightModel.PrimaryPart.Position.X,
						lightModel.PrimaryPart.Position.Y + math.random(2, 3),
						lightModel.PrimaryPart.Position.Z + math.random(2, 4)
						)
					)
                if lightModel:FindFirstChild("Light1") then
		            lightModel.Light1.light.Enabled = true 
                end
                if lightModel:FindFirstChild("Light2") then
			        lightModel.Light2.light.Enabled = false 
                end
			end
			
			wait(waitDelay)
			for _,lightModel in pairs(StageLights:GetChildren()) do  
                if lightModel:FindFirstChild("Light1") then 
                    lightModel.Light1.light.Enabled = false
                end 
                if lightModel:FindFirstChild("Light2") then
                    lightModel.Light2.light.Enabled = true
                end
			end
		end
	end
end