Displaying Player Speed

Hi! I’m trying to display the speed of a player in a TextLabel. I’ve found a few ways to do this, one of which used HumanoidRootPart.Velocity.Magnitude but wasn’t quite what I was looking for.

For reference, the popular game surf uses something similar to what I’d like.

When standing still, the UI displays 0.00 u/s
image

When walking, it displays 18.00 u/s and everything in between (acceleration, deceleration)
image

How would I go about this? I’m assuming the solution is pretty simple, but I’m completely in the dark here.

Any help would be greatly appreciated.

2 Likes

Try doing

(Character.PrimaryPart.AssemblyLinearVelocity * Vector3.new(1, 0, 1)).Magnitude
1 Like

This worked, however constantly updates tiny numbers when standing still.
image

How would I go about just showing two decimal places?

Use this function

function roundingWithDecimals(x, decimals)
	decimals = decimals or 0
	return math.floor(n * 10^decimals) / 10^decimals
end
1 Like

essentially do

speed = roundingWithDecimals((Character.PrimaryPart.AssemblyLinearVelocity * Vector3.new(1, 0, 1)).Magnitude, 2)

Because this is a value returning function

sorry. but what does the “n” in “math.floor(n * 10^decimals)” mean?

Mistype, it should be x instead of n. It is the number you want to round

oh alright. I figured it out as well during that time gap. thanks for your help i managed to make Speed Lines around the player screen using that. thanks alot