Trying to script a simple railway block signal

I am trying to create a railway block signal, and the following script isn’t working. There’s a seperate script that handles the sensor, which works fine. This script is meant to allow the signal to be easily modified by only needing one value to be changed (The end of the top variable)
I don’t know why, but this script doesn’t work, no errors, just doesn’t change the state, the signal never changes from red

local NextSignal = script.Parent.Parent.Signal_A003
local Sensor = script.Parent.Sensor
local debounce = false
local State = script.Parent.State.Value
local Code = script.Parent.Parent.Name
local Click = script.Parent.Click
local L1 = script.Parent.L1
local L2 = script.Parent.L2
--End of variables
--
--Main Code
while true do
	wait()
	if NextSignal.State.Value == "Red" then
		wait(5)--Time to wait until signal state changes, this should allow the train infront to clear the block before allowing another train through
		L1.BrickColor = BrickColor.new("Neon orange")
		L2.BrickColor = BrickColor.new("Neon orange")
		State = "Orange"
		--This changes the state of the signal and the lights
	elseif NextSignal.State.Value == "Orange" then
		wait(5)--Time to wait until signal state changes, this should allow the train infront to clear the block before allowing another train through
		L1.BrickColor = BrickColor.new("Lime green")
		L2.BrickColor = BrickColor.new("Really black")
		State = "Green"
		--This changes the state of the signal and the lights
	elseif NextSignal.State.Value == "Green" then
		--Nothing happens here as if the signal infront is green, nothing should be done
	end
end

I would appreciate any help I can get, feel free to ask questions!

I’m guessing the issue is that you’re writing directly to the State variable. I would assume you’re actually trying to write to the ValueObject’s value directly. If that’s the case, when you index the Value property of State, that’s gonna pass its value to the variable, it’s not going to point to that property if that makes sense. So with that being said, index the Value property when you need it; don’t store it as a property as all that does is store the value of the object.

e.g:

State.Value = "Orange"
1 Like

I think your State variable is referring wrong. Why don’t you do NextSignal.State.Value = "Color" instead of State = "Color"

1 Like