How to detect when the car is moving

So I’m trying to make a basic system where the car drains oil as it moves but I can’t figure it how to do this.

This uses the Roblox built in car system.

driveSeat.Changed:Connect(function(property)
	if property == "ThrottleFloat" then
		leftMotor.AngularVelocity = MAX_SPEED * driveSeat.ThrottleFloat
		rightMotor.AngularVelocity = MAX_SPEED * driveSeat.ThrottleFloat
	elseif property == "SteerFloat" then
		leftServo.TargetAngle = MAX_STEER * driveSeat.SteerFloat
		rightServo.TargetAngle = MAX_STEER * driveSeat.SteerFloat
	end
end)

When I try put this under driveseat.Changed it only drains when the car changes direction.

And checking if the position or velocity changes doesn’t work

So now I have no idea how to do this
Could someone help?

1 Like

You need a constant loop, preferably in a LocalScript because these effects shouldn’t be handled on the server.

local runService = game:GetService("RunService")
runService.PreRender:Connect(function(dt)
--code here for the oil draining
end)

A constant loop I know but how do I detect when the car is moving

if carSeat.AssemblyLinearVelocity.Magnitude > 4 then
--the car is moving!
end

The 4 is studs per second.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.