function StationService:StationLeave(trainSettings)
runned = false
for _, StationsInFolder in pairs(mTrackFolder:GetChildren()) do
if StationsInFolder.Name == trainSettings.StationName.Value then
runned = true
for _, NextStationsInFolder in pairs(mTrackFolder:GetChildren()) do
if NextStationsInFolder.Name == StationsInFolder.Configuration.NextStation.Value then
local redLight = NextStationsInFolder.Signal.RedLight
local greenLight = NextStationsInFolder.Signal.GreenLight
while true do
local r, g, b = greenLight.Color.R * 255, greenLight.Color.G * 255, greenLight.Color.B * 255
print(string.format("GreenLight RGB: %d, %d, %d", r, g, b))
if NextStationsInFolder.Configuration.Occupied.Value == true then
warn(NextStationsInFolder.Name, " is currently occupied!")
elseif redLight.Color == Color3.fromRGB(151, 0, 0) then
warn(NextStationsInFolder.Name, " is currently on a red light!")
elseif greenLight.Color == Color3.fromRGB(255, 255, 0) then
warn(NextStationsInFolder.Name, " is currently on a yellow light!")
else
break
end
wait(0.25)
end
StationsInFolder.Configuration.Occupied.Value = false
trainSettings.StationName.Value = StationsInFolder.Configuration.NextStation.Value
end
end
if runned == false then
warn("No station leave action was complete!")
end
end
end
end```
#light color change detection not working?
1 messages · Page 1 of 1 (latest)
so you can see in the video the light changes while the while loop is running and yet it detects no color change.
the code is supposed to only let the train run when the light isnt red or yellow and isnt occupied
the occupied bit works but the color detection is not
Anyone?
** You are now Level 7! **
the issue seems to be with how you’re checking the Color3 values in a loop. Color3 comparison using == can be unreliable if the color is set via script or tweening (as float precision may slightly change).
⸻
Problem Summary
Your code: elseif redLight.Color == Color3.fromRGB(151, 0, 0) then
Fix 1: Use Color3:ToHex() or RGB rounding for comparison
Here’s how you can fix it using rounded RGB values:
Updated while loop portion: while true do
local rG, gG, bG = math.floor(greenLight.Color.R * 255 + 0.5), math.floor(greenLight.Color.G * 255 + 0.5), math.floor(greenLight.Color.B * 255 + 0.5)
local rR, gR, bR = math.floor(redLight.Color.R * 255 + 0.5), math.floor(redLight.Color.G * 255 + 0.5), math.floor(redLight.Color.B * 255 + 0.5)
print(string.format("GreenLight RGB: %d, %d, %d", rG, gG, bG))
if NextStationsInFolder.Configuration.Occupied.Value == true then
warn(NextStationsInFolder.Name, " is currently occupied!")
elseif rR == 151 and gR == 0 and bR == 0 then
warn(NextStationsInFolder.Name, " is currently on a red light!")
elseif rG == 255 and gG == 255 and bG == 0 then
warn(NextStationsInFolder.Name, " is currently on a yellow light!")
else
break
end
task.wait(0.25)
end
||In summary heres the Updated while loop portion: while true do
local rG, gG, bG = math.floor(greenLight.Color.R * 255 + 0.5), math.floor(greenLight.Color.G * 255 + 0.5), math.floor(greenLight.Color.B * 255 + 0.5)
local rR, gR, bR = math.floor(redLight.Color.R * 255 + 0.5), math.floor(redLight.Color.G * 255 + 0.5), math.floor(redLight.Color.B * 255 + 0.5)
print(string.format("GreenLight RGB: %d, %d, %d", rG, gG, bG))
if NextStationsInFolder.Configuration.Occupied.Value == true then
warn(NextStationsInFolder.Name, " is currently occupied!")
elseif rR == 151 and gR == 0 and bR == 0 then
warn(NextStationsInFolder.Name, " is currently on a red light!")
elseif rG == 255 and gG == 255 and bG == 0 then
warn(NextStationsInFolder.Name, " is currently on a yellow light!")
else
break
end
task.wait(0.25)
end
Did you just ChatGPT this
No
You know the while loop portion
Update it with this
while true do
local rG, gG, bG = math.floor(greenLight.Color.R * 255 + 0.5), math.floor(greenLight.Color.G * 255 + 0.5), math.floor(greenLight.Color.B * 255 + 0.5)
local rR, gR, bR = math.floor(redLight.Color.R * 255 + 0.5), math.floor(redLight.Color.G * 255 + 0.5), math.floor(redLight.Color.B * 255 + 0.5)
print(string.format("GreenLight RGB: %d, %d, %d", rG, gG, bG))
if NextStationsInFolder.Configuration.Occupied.Value == true then
warn(NextStationsInFolder.Name, " is currently occupied!")
elseif rR == 151 and gR == 0 and bR == 0 then
warn(NextStationsInFolder.Name, " is currently on a red light!")
elseif rG == 255 and gG == 255 and bG == 0 then
warn(NextStationsInFolder.Name, " is currently on a yellow light!")
else
break
end
task.wait(0.25)
end
I call bullshit on that.
try it
I'm not the one with this issue, I'm just calling you out on your ChatGPT laziness.
The fact that this looks so damn AI it hurts, it's such a common ChatGPT format, using symbols not normally used in a Discord message in casual conversation
Like "Problem Summary" seriously?