- I ran into a problem: when a player exits a car while it's moving, it continues to coast, but I wanted it to stop (either instantly, or at least try to brake, somehow).
- More info in the next message, otherwise it's over the limit.
wait(0.2)
local seat = script.Parent
local car = seat.Parent
if not car then
warn("Autostop: Car not found!")
return
end
local wheels = car:WaitForChild("Wheels", 5)
if not wheels then
warn("Autostop: Wheels not found!")
return
end
local BRAKE_FORCE = 15000
local MIN_SPEED = 0.5
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if not seat.Occupant then
seat.Throttle = 0
seat.Steer = 0
local brakeForce = Instance.new("BodyForce")
brakeForce.Name = "AutoBrake"
brakeForce.Parent = seat
task.spawn(function()
while brakeForce and brakeForce.Parent do
local velocity = seat.AssemblyLinearVelocity
local speed = velocity.Magnitude
if speed < MIN_SPEED then
brakeForce:Destroy()
break
end
local brakeVector = velocity.Unit * -BRAKE_FORCE
brakeForce.Force = brakeVector
task.wait(0.1)
end
end)
end
end)