local Seat = script.Parent
local Train = Seat.Parent
local Body = Train.Body
local LBogie = Train.LBogie
local RBogie = Train.RBogie
local FCoupler = Train.FrontCoupler
local BCoupler = Train.BackCoupler
local vel = script.Parent.Parent.Body.BodyAngularVelocityVelocity
local Velocity = 0
speed = 100
acceleration = 0.1
deceleration = 0.2
Seat.Changed:connect(function(type)
if type == "Throttle" then
local Input = Seat.Throttle
repeat
Velocity = Velocity+Input
if Input*Velocity/math.abs(Velocity) == -1 then
wait(1/script.Deceleration.Value)
else
wait(1/script.Acceleration.Value)
end
if Velocity > script.MaxSpeed.Value then
Velocity = script.MaxSpeed.Value
elseif Velocity < -script.MaxSpeed.Value then
Velocity = -script.MaxSpeed.Value
end
until Seat.Throttle ~= Input
end
end)
while script.Parent ~= nil do
wait()
vectorpower = script.MaxPower.Value*Seat.CFrame.lookVector
vel.MaxTorque = Vector3.new(vectorpower.X>0 and vectorpower.X or -vectorpower.X,
vectorpower.Y>0 and vectorpower.Y or -vectorpower.Y,
vectorpower.Z>0 and vectorpower.Z or -vectorpower.Z
)
vel.Velocity = Velocity*Seat.CFrame.lookVector
end
I am having issues with this where the locomotive just levitates in the air, this might also be bc of the properties on it but if it is, please let me know.