Why is the actual distance taken to decelerate different to the calculated one?

Hi! I’ve been trying to code an elevator (although this could be applied to really anything) where the elevator slows down with a constant speed. I’ve got a really bizarre issue where the actual distance taken to slow down to 0 is longer than what is calculated, yet it still takes exactly 2 seconds. I don’t know if this is an issue with Roblox or with my calculation.
The calcuation that determins the speed is s=-12.5(t)+25, where s is speed, t is time since the start of slowing down, and -12.5 is the rate of stopping (in studs/second^2), which means a full stop from 25 sps should take 2 seconds, which it does. This results in the elevator having travelled about 30.6 studs since it started slowing down.
The thing is that you need to be able to know when to start slowing down, which is why I found an equation online to find the distance that an object will take while slowing down. It is:
image
where s is distance, vi is initial velocity, t is time, and a is acceleration (which would be negative for deceleration). I converted this to work in a line of code like this:
(vi*t)+0.5*(a*math.pow(t, 2))
However, plugging in the numbers I have: (25*2)+0.5*(-12.5*math.pow(2, 2)) results in a distance of 25, which is too low and always results in the elevator overshooting the floor.
I’ve been trying tons of things to figure out what possibly could be resulting in the mismatch between calculated and actual, to no avail. The only thing I can do is put 30.6 in as the slowdown point, which means it only works from full speed, which is not helpful.
Thanks in advance!

In this case, negative acceleration does not mean decelerating, it just means distance is moving in the negative direction. If you want a decelerating effect, you need to come from the part of the graph where it is “slowing down” (in precise terms, the second derivative is negative). So to achieve this you just need to offset your input time value.

Also, you don’t need to use the function math.pow, you can just use the exponentiation operator ^.

I’m not particularly too sure what you mean by “offsetting the time value.” Can you give me an example? The graph that is actually controlling the speed (first equation) is in the downward direction as time increases, and I’m not too sure how you’d offset the second equation (the one derives the distance).