Hello! I’m making a traffic light. When I was done building it, I ran into a problem in the code (no errors).
Here’s how I the signal’s organized:
The values are bools to control the light.
Here’s my script in each traffic light:
Signal 1:
local lightValue = script.Parent.Parent["Light 1"]
local red = script.Parent.Red
local yellow = script.Parent.Yellow
local green = script.Parent.Green
local redLight = red.SurfaceLight
local yellowLight = yellow.SurfaceLight
local greenLight = green.SurfaceLight
wait(2)
if lightValue.Value == true then
red.Color = Color3.fromRGB(86, 36, 36)
redLight.Enabled = false
green.Color = Color3.fromRGB(0, 255, 0)
greenLight.Enabled = true
end
if lightValue.Value == false then
green.Color = Color3.fromRGB(39, 70, 45)
greenLight.Enabled = false
yellow.Color = Color3.fromRGB(255, 255, 0)
yellowLight.Enabled = true
wait(3)
yellow.Color = Color3.fromRGB(86, 66, 54)
yellowLight.Enabled = false
redLight.Enabled = true
red.Color = Color3.fromRGB(255, 0, 0)
end
Signal 2:
local lightValue = script.Parent.Parent["Light 2"]
local red = script.Parent.Red
local yellow = script.Parent.Yellow
local green = script.Parent.Green
local redLight = red.SurfaceLight
local yellowLight = yellow.SurfaceLight
local greenLight = green.SurfaceLight
wait(2)
redLight.Enabled = true
red.Color = Color3.fromRGB(255, 0, 0)
if lightValue.Value == true then
red.Color = Color3.fromRGB(86, 36, 36)
redLight.Enabled = false
green.Color = Color3.fromRGB(0, 255, 0)
greenLight.Enabled = true
end
if lightValue == false then
green.Color = Color3.fromRGB(39, 70, 45)
greenLight.Enabled = false
yellow.Color = Color3.fromRGB(255, 255, 0)
yellowLight.Enabled = true
wait(3)
yellow.Color = Color3.fromRGB(86, 66, 54)
yellowLight.Enabled = false
redLight.Enabled = true
red.Color = Color3.fromRGB(255, 0, 0)
end
Script that handles both:
local lightBool1 = script.Parent["Light 1"]
local lightBool2 = script.Parent["Light 2"]
while true do
lightBool1.Value = true
lightBool2.Value = false
wait(5)
lightBool2.Value = true
lightBool1.Value = false
wait(5)
end
Any suggestions on how to fix this?