Vehicle Speedometer

I have a speedometer system and I want to get Vehicle Speed changes without using “while true do” or “repeat”. Like is there a way to get any sort of changes that Roblox system can pick up on it’s own and connect to with a function?

4 Likes

Assign the speed to the value property of a NumberValue instance then do the following.

local speed = Instance.new("NumberValue")
speed.Parent = nil --parent the number value somewhere
speed.Value = nil --assign the vehicle speed constantly here
	
speed.Changed:Connect(function(newSpeed)
	--do code
end)

Because you have a speedometer system I assume you are using Body Velocity or some sort of Body mover. Even though I have no reason to assume that,it seems to have a greater chance.
In that case, you can use the “GetPropertyChangedSignal” method which every instance in the game Inherits from the “Instance” class.
just for example I would do this -

local bodyVelocity = -- path 
bodyVelocity:GetPropertyChangedSignal("Velocity"):Connect(function()

    --    local speedometer = --path
    --    speedometer.Value = bodyVelocity.Velocity.Magnitude

end
3 Likes

You could use heartbeat with a part…

local part
local mag
local heartbeat_connection = game:GetService('Heartbeat'):Connect(function()
	local part_mag = part.Velocity.Magnitude
	if mag ~= part_mag then
		--//Detection Aquired
	end
	mag = part_mag
end)

Can you do an example with it using a vehicleseat? Cause it the program won’t pick it up.

1 Like

just do this, taken from nootian


local mag;
local heartbeat_connection = game:GetService("RunService").Heartbeat:Connect(function()
	local part_mag = VehicleSeat.Velocity.Magnitude
	if mag ~= part_mag then
   --example code for sound
	local velocity = (VehicleSeat.Position - lastPos)
	lastPos = VehicleSeat.Position
	carSound.PlaybackSpeed = (0.3 + velocity.Magnitude/5)

	end
    mag = part_mag
end)