`AssemblyLinearVelocity.Magnitude` returns 1 even when not moving

Hi there!
I’m trying to script a car. Everything was going well until I saw that my speedometer stays at 1 KPH even when I’m not moving.

How can I fix this??

Here’s my code to set the speed on the label:

local runService = game:GetService("RunService")

local speedometer = script.Parent
local speedLabel = speedometer.Speed

local car = speedometer.Parent.Car.Value
local chassis = car:WaitForChild("Chassis")

local conversionCoeff = 1.0

runService.RenderStepped:Connect(function()
	
	local speed = chassis.AssemblyLinearVelocity.Magnitude
	
	speedLabel.Text = math.max(0, math.floor(speed))
	
end)

you’re probably getting this issue because of some Veeery small movements in simulation. to fix it i think you could try adding a small threshold check, to set values very close to 0 to 0. for example

local speedThreshold = 0.1

and we check if speed is less than 0.1 aka the speedThreshold.

  if speed < speedThreshold then
        speed = 0
    end

Thank you, it worked! ( extra characters )

1 Like

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