I’d recommend the pre-physics one in a more “let loose” while loop based system
It works more with the system, using the exact time of the previous frame to determine how far it should go based on that and the speed, not hoping the time will be a specific value and that there’s no lag or any other issues
Runservice also has twice the accuracy as wait() at its best and this system also prevents FPS unlockers from creating ultra speedy trains as funny as that’d be
local rs = game:GetService("RunService")
function lerp(cart,node)
local prev = --get CFrame of previous mode
local curr = --get CFrame of current node
local distance = (prev.p-curr.p).Magnitude
local d = 0
while d <= distance do
cart.CFrame = prev:Lerp(curr, d/distance)
local dt = rs.Stepped:Wait()
d = d + cart.CartSpeed.Value * dt
end
cart.CFrame = curr
end
This should function fairly similar to your current one and you can change the speed whenever you so desire
It’s probably not set up exactly how you’d want it to be so you’ll prob have to do some manual editing, but all of the math is there
There’s one disbenefit to this exact setup, on the very last frame before the cart reaches the node, the train does not move its actual speed for that last 60th of a second
A simple way to fix this would be to return the “excess” distance and simply add it onto d for the next node
For example:
local rs = game:GetService("RunService")
function lerp(cart,node,leftovers)
local prev = --get CFrame of previous mode
local curr = --get CFrame of current node
local distance = (prev.p-curr.p).Magnitude
local d = leftovers
while d <= distance do
cart.CFrame = prev:Lerp(curr, d/distance)
local dt = rs.Stepped:Wait()
d = d + cart.CartSpeed.Value * dt
end
return d-distance
end
KEEP IN MIND that this has to be set up in the code where you run the lerp function, in a way similar to this, but it doesn’t have to be exact:
local leftovers = 0
for node = 1, #NODES do --just guessing smthn random
leftovers = lerp(cart, node, leftovers)
end
Again it doesn’t have to be exactly this, just along the lines of this so that the return value of the previous function gets passed on to the following function
Also make sure none of the nodes are the same exact position it’ll break it