-
What do you want to achieve? Keep it simple and clear!
If the crossroad is active it should break the loop for the white light. And it should run the loop again when false. -
What is the issue?
It doesnt break the loop.
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Yes, but they didn’t work
The red lights work with a variable that gives a boolean if its active or not. So i check if its false so the white light turns on. Each light has it own script in the part itself.
White light:
local sourceLight = script.Parent
local lightCover = sourceLight.Parent:GetChildren()
local crossroadActive = game.Workspace.CrossroadLight.Active.Value
local lightStart = game.Workspace.LightCheck
local lightStop = game.Workspace.LightStop
local TweenService = game:GetService("TweenService")
local whiteLight = {Color = Color3.fromRGB(216, 216, 216)}
local offLight = {Color = Color3.fromRGB(29,29,29)}
local info = TweenInfo.new(0.75, Enum.EasingStyle.Circular, Enum.EasingDirection.InOut, 0, false, 0)
while crossroadActive == false do
wait(0.75)
local tweenLightToWhite = TweenService:Create(sourceLight, info, whiteLight)
tweenLightToWhite:Play()
sourceLight.SpotLight.Enabled = true
wait(0.75)
local tweenLightToOff = TweenService:Create(sourceLight, info, offLight)
tweenLightToOff:Play()
sourceLight.SpotLight.Enabled = true
if crossroadActive then
break
end
end
The two red lights have almost the same script (only difference is the wait):
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 == false then
crossroadActive = true
wait(0.5)
while crossroadActive do
wait(0.5)
for i,v in pairs(lightCover) do --transition to red
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
wait(0.5)
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 = false
end
end)```
Thanks in advance!

