You can write your topic however you want, but you need to answer these questions:
I am making a traffic light algorithm for a set of lights at an intersection in my game
For some reason the thread is running 4.5 seconds after all the other ones start, which doesnt make sense because the wait(4.5) is inside the function because the yellow light as a delay
Literally tried everything to solve, for some reason when i put 1 of the turning lights lower in the task.spawn(s) it runs perfectly but when the other one gets near it they both get a delay
This is the calling script
local TrafficModule = require(script.Parent.TrafficModule)
local function TurnOntoPrincesHwyNorthBound()
-- Change signals
task.spawn(function()
TrafficModule.GoRedLight(TrafficModule.RightTurnAndSingleLights.RightTurnAndSingleLight2, true, true)
task.wait(4.5)
TrafficModule.GoGreenLight(TrafficModule.SingleLights.Single3, false)
TrafficModule.GoGreenArrow(TrafficModule.LeftTurnAndSingleLights.LeftTurnAndSingleLight1, false)
end)
task.spawn(function()
TrafficModule.GoRedLight(TrafficModule.RightTurnAndSingleLights.RightTurnAndSingleLight4, true, true)
task.wait(4.5)
TrafficModule.GoGreenLight(TrafficModule.SingleLights.Single5, false)
end)
task.spawn(function()
print("I AM RUNNING")
TrafficModule.GoRedArrow(TrafficModule.RightTurnLights.RightTurn1)
end)
task.spawn(function()
TrafficModule.GoRedLight(TrafficModule.SingleLights.Single2, false, false)
task.wait(4.5)
TrafficModule.GoGreenLight(TrafficModule.LeftTurnAndSingleLights.LeftTurnAndSingleLight2, true)
end)
task.spawn(function()
TrafficModule.GoRedLight(TrafficModule.SingleLights.Single1, false, false)
task.wait(4.5)
TrafficModule.GoGreenLight(TrafficModule.LeftTurnAndSingleLights.LeftTurnAndSingleLight4, true)
end)
task.spawn(function()
TrafficModule.GoRedLight(TrafficModule.SingleLights.Single6, false, false)
end)
task.spawn(function()
TrafficModule.GoRedLight(TrafficModule.RightTurnAndSingleLights.RightTurnAndSingleLight1)
TrafficModule.GoRedArrow(TrafficModule.RightTurnLights.RightTurn2)
end)
task.spawn(function()
TrafficModule.GoRedLight(TrafficModule.RightTurnAndSingleLights.RightTurnAndSingleLight3, true, true)
end)
task.spawn(function()
TrafficModule.GoRedLight(TrafficModule.RightTurnAndSingleLights.RightTurnAndSingleLight3, true, true)
end)
task.spawn(function()
TrafficModule.GoRedLight(TrafficModule.LeftTurnAndSingleLights.LeftTurnAndSingleLight1, false, false)
end)
end
This is the function inside the module script
function TrafficFunctions.GoRedArrow(Light)
-- Turn on Yellow Arrow
print("Turning on Yellow Arrow")
Light.YellowArrow.Transparency = 0
Light.YellowArrow.PointLight.Brightness = 1
Light.YellowArrow.Material = Enum.Material.Neon
wait(4.5)
-- Turn off Yellow Arrow
print("Turning off Yellow Arrow, turning on Red Arrow")
Light.YellowArrow.Transparency = 0.8
Light.YellowArrow.PointLight.Brightness = 0
Light.YellowArrow.Material = Enum.Material.SmoothPlastic
-- Turn on Red Arrow
Light.RedArrow.Transparency = 0
Light.RedArrow.PointLight.Brightness = 1
Light.RedArrow.Material = Enum.Material.Neon
end
I’m losing my mind I need help please