How to calculate how many studs a second a part is moving

Basically, here’s my code for a part moving:

repeat
script.Parent.Position += Vector3.new(-2, 0, 0)
wait(0)
until whatever

since my part is moving 2 blocks away every wait(0), how fast is it moving?
I need help with this so I can calculate how long it should take for it to get faster
Edit: since i want it to change after entering a certain amount of rooms, i did this:
30 (wait(0)s in a second (i think)) * 2 (speed) / 56 (length of room) = 1.07 rooms per second
Would that work?

You can use the simple formula:

speed = distance/time

You would save the position before you add the wait in a variable and then you’d divide that by the wait amount…

In your case it would look something like:

local Speed = (script.Parent.Position - savedPosition).Magnitude / waitTime

I will try this, thanks.

character limit uehgueghueghueg

1 Like

By the way, if you’re gonna do something like that you might as well use Heartbeat or RenderStepped

Part.Velocity.Magnitude

Using that will return the studs per second a part is moving on every axis.

If you want only the X and Z speed, you can create a new vector using the velocities X and Z, but setting Y to zero.

--// Get the velocity Vector
local Velocity = Part.Velocity

 --// Change the vector to a number and update the variable
Velocity = Vector3.new(Velocity.X, 0, Velocity.Z).Magnitude
1 Like