SpeedSensor (2-Way)
Overview
Features
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
Variable
Type
Description
How It Works
Usage Guide
Example
Best Practices
Last updated