I think you need to apply the same changes to the other for loop, posting the updated code would help.
Already did. Here’s the code:
Red light left:
local sourceLight = script.Parent
local lightCover = sourceLight.Parent:GetChildren()
local crossroadActive = game.Workspace.CrossroadLight.Active
local lightStart = game.Workspace.LightCheck
local lightStop = game.Workspace.LightStop
local TweenService = game:GetService("TweenService")
local redLight = {Color = Color3.fromRGB(255,0,0)}
local redCover = {Color = Color3.fromRGB(0,0,0)}
local offLight = {Color = Color3.fromRGB(29,29,29)}
local offCover = {Color = Color3.fromRGB(65,65,65)}
local info = TweenInfo.new(0.5, Enum.EasingStyle.Circular, Enum.EasingDirection.InOut, 0, false, 0)
lightStart.Touched:Connect(function(otherPart)
local humanoid = otherPart.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid and crossroadActive.Value == false then
crossroadActive.Value = true
while crossroadActive.Value do
for i,v in pairs(lightCover) do --transition to red
if i == #lightCover/2 then
task.wait(0.5)
end
sourceLight.SpotLight.Enabled = true
if v.Name == "SourceLight" then
local tweenLightToRed = TweenService:Create(v, info, redLight)
tweenLightToRed:Play()
else
local tweenCoverToRed = TweenService:Create(v, info, redCover)
tweenCoverToRed:Play()
end
end
for i,v in pairs(lightCover) do --transition to off
sourceLight.SpotLight.Enabled = false
if v.Name == "SourceLight" then
local tweenLightToOff = TweenService:Create(v, info, offLight)
tweenLightToOff:Play()
else
local tweenCoverToOff = TweenService:Create(v, info, offCover)
tweenCoverToOff:Play()
end
end
end
end
end)
lightStop.Touched:Connect(function(otherPart)
local humanoid = otherPart.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
crossroadActive.Value = false
end
end)
Red light right:
local sourceLight = script.Parent
local lightCover = sourceLight.Parent:GetChildren()
-- we walk all the way up parent after parent to LeftLight to get it's children
-- it's fragile because of how many parent's we have to go through
for _, leftChild in ipairs(sourceLight.Parent.Parent.Parent.LeftLight.Light:GetChildren()) do
table.insert(lightCover, leftChild)
end
local crossroadActive = game.Workspace.CrossroadLight.Active
local lightStart = game.Workspace.LightCheck
local lightStop = game.Workspace.LightStop
local TweenService = game:GetService("TweenService")
local redLight = {Color = Color3.fromRGB(255,0,0)}
local redCover = {Color = Color3.fromRGB(0,0,0)}
local offLight = {Color = Color3.fromRGB(29,29,29)}
local offCover = {Color = Color3.fromRGB(65,65,65)}
local info = TweenInfo.new(0.5, Enum.EasingStyle.Circular, Enum.EasingDirection.InOut, 0, false, 0)
lightStart.Touched:Connect(function(otherPart)
local humanoid = otherPart.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid and crossroadActive.Value == false then
crossroadActive.Value = true
while crossroadActive.Value do
for i,v in pairs(lightCover) do --transition to red
sourceLight.SpotLight.Enabled = true
if i == #lightCover/2 then
task.wait(0.5)
end
if v.Name == "SourceLight" then
local tweenLightToRed = TweenService:Create(v, info, redLight)
tweenLightToRed:Play()
else
local tweenCoverToRed = TweenService:Create(v, info, redCover)
tweenCoverToRed:Play()
end
end
for i,v in pairs(lightCover) do --transition to off
sourceLight.SpotLight.Enabled = false
if v.Name == "SourceLight" then
local tweenLightToOff = TweenService:Create(v, info, offLight)
tweenLightToOff:Play()
else
local tweenCoverToOff = TweenService:Create(v, info, offCover)
tweenCoverToOff:Play()
end
end
end
end
end)
lightStop.Touched:Connect(function(otherPart)
local humanoid = otherPart.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
crossroadActive.Value = false
end
end)
You’ll have to mess around with these waits a little more, but I meant to add the #lightCover/2 check to the end transition part like so
sourceLight.SpotLight.Enabled = true
for i,v in pairs(lightCover) do --transition to red
if i == #lightCover/2 then
task.wait(0.5)
end
if v.Name == "SourceLight" then
local tweenLightToRed = TweenService:Create(v, info, redLight)
tweenLightToRed:Play()
else
local tweenCoverToRed = TweenService:Create(v, info, redCover)
tweenCoverToRed:Play()
end
end
task.wait(0.5) -- try this out too, maybe delete
sourceLight.SpotLight.Enabled = false
for i,v in pairs(lightCover) do --transition to off
if i == #lightCover/2 then
task.wait(0.5)
end
if v.Name == "SourceLight" then
local tweenLightToOff = TweenService:Create(v, info, offLight)
tweenLightToOff:Play()
else
local tweenCoverToOff = TweenService:Create(v, info, offCover)
tweenCoverToOff:Play()
end
end
Oh sorry. This is all very new for me. I will test it out tomorrow. thx