Calculating a part's time of arrival

local prismaticCon = pusher.PrismaticConstraint

prismaticCon.ServoMaxForce = (pusher:GetMass() + coinPushHandler.Inside:GetMass()) * 10
prismaticCon.TargetPosition = 50

task.wait(prismaticCon.TargetPosition/prismaticCon.Speed)

print("Finished")

I’m currently trying to make a pusher that pushes parts forward similar to a piston by using prismaticConstraints. I’m trying to get calculate the time of arrival of the pusher by dividing the PrismaticConstraint’s TargetPosition by the PrismaticConstraint Speed however it prints Finished a second or two before the object reaches the TargetPosition. What can I do to get the exact time of arrival?

On an unrelated note, is there a better way to make a piston altogether? I previously used TweenService and that allowed me to determine when the object has reached the goal CFrame and then tween back, however, tweening doesn’t account for physics and the objects being pushed would clip into the pusher. Any help is appreciated!

Use task.wait until PrismaticConstraint.CurrentPosition < PrismaticConstraint & then print(“finished”)
Depending on your setup you may need => or =<, but don’t just use = because the value would need to be exactly the same.

Why are you trying to calculate the ServoMaxForce anyway? You can just set it to a very high value (I read somewhere that setting it at math.huge or inf may cause some physics issues) which won’t cause problems even if the number of coins is zero.

Distane / Speed = Time

speed-triangle

If you look at the script you’ll see that @UnderEvaluation used that exact formula in this line:
task.wait(prismaticCon.TargetPosition/prismaticCon.Speed)

Yes, time = distance/speed, but they are dealing with lag as well, so they want to know when the TargetPosition is actually reached, not how to calculate when it should be reached.