SpeedSensor (2-Way)
Overview
The SpeedSensor (2-Way) is an advanced trackside sensor for the Railux 6 Ultra train system.
It controls train speed limits and ATO target speeds for trains traveling in either direction (forward or reverse), and optionally when stopped.
Features
Sets speed and ATO target speed based on train movement direction.
Supports up to 3 directions:
Direction A: Forward (speed > 0)
Direction B: Reverse (speed < 0)
Direction C: Stopped (speed = 0, optional)
Configurable debounce time to prevent repeat triggers.
Optionally hides the sensor part in-game for a clean look.
Script Reference
-- Direction A (Forward)
local SpeedLimitA = 50
local TargetSpeedA = 50
-- Direction B (Reverse)
local SpeedLimitB = -50
local TargetSpeedB = -50
-- Direction C (Stopped, Optional)
local Enable_C = false
local SpeedLimitC = 0
local TargetSpeedC = 0
local DebounceTime = 15
local TransparentInGame = false
-- DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING
script.Parent.DirectionGuide:Destroy()
local Debounce = false
if TransparentInGame == true then
script.Parent.Transparency = 1
end
script.Parent.Touched:Connect(function(child)
if child.Name == "TrainTouchSensor" and Debounce == false then
Debounce = true
local speed = child.Parent.Parent.Parent.API.Propulsion.Speed.Value
if speed > 0 then
child.Parent.Parent.Parent.API.Propulsion.SpeedLimit.Value = SpeedLimitA
child.Parent.Parent.Parent.API.Propulsion.TargetSpeed.Value = TargetSpeedA
elseif speed < 0 then
child.Parent.Parent.Parent.API.Propulsion.SpeedLimit.Value = SpeedLimitB
child.Parent.Parent.Parent.API.Propulsion.TargetSpeed.Value = TargetSpeedB
else
if Enable_C == true then
child.Parent.Parent.Parent.API.Propulsion.SpeedLimit.Value = SpeedLimitC
child.Parent.Parent.Parent.API.Propulsion.TargetSpeed.Value = TargetSpeedC
end
end
task.wait(DebounceTime)
Debounce = false
end
end)Configuration
SpeedLimitA
Number
Max speed (SPS) for trains moving forward (Speed > 0) which is shown to the driver. (if present)
TargetSpeedA
Number
ATO target speed (SPS) for trains moving forward.
SpeedLimitB
Number
Max speed (SPS) for trains moving backward (Speed < 0) which is shown to the driver. (if present)
TargetSpeedB
Number
ATO target speed (SPS) for trains moving backward.
Enable_C
Boolean
Set to true to enable Direction C (stopped, Speed = 0), otherwise ignored.
SpeedLimitC
Number
Max speed (SPS) if train is stopped on the sensor (rare, mostly for special cases) which is shown to the driver. (if present)
TargetSpeedC
Number
ATO target speed (SPS) if train is stopped.
DebounceTime
Number
Time (in seconds) before the sensor can trigger again after activation.
TransparentInGame
Boolean
If true, makes the sensor invisible in-game (Transparency = 1).
How It Works
Initialization:
Destroys the attached
DirectionGuidepart.Makes the sensor invisible if
TransparentInGameistrue.
Touch Event:
When a
"TrainTouchSensor"part touches the sensor and debounce is off:Reads the train’s current speed.
Applies the appropriate speed and ATO targets:
Forward: Uses Direction A settings (
Speed > 0)Reverse: Uses Direction B settings (
Speed < 0)Stopped: Uses Direction C settings if
Enable_Cistrue(Speed = 0)
Debounce activates for
DebounceTimeseconds to prevent retriggering.
Usage Guide
Install the sensor part where two-way speed enforcement is needed (e.g., at crossovers or bi-directional tracks).
Configure parameters at the top of the script for each direction as needed.
Ensure trains have a
"TrainTouchSensor"part.Use
Enable_Conly for special cases (e.g., for enforcing rules when stopped on the sensor).
Example
To set different speeds for each direction and make the sensor invisible:
local SpeedLimitA = 80
local TargetSpeedA = 70
local SpeedLimitB = -60
local TargetSpeedB = -60
local Enable_C = false
local DebounceTime = 10
local TransparentInGame = trueBest Practices
Set Direction B values as negative if your system uses negative speeds for reverse.
Test both directions to ensure the correct limits are applied.
Use Direction C only if you have a specific rule for stopped trains.
Adjust
DebounceTimebased on train length and traffic.
Last updated