I'm making a machine in which a cup will go on a conveyor belt to get filled with juice, this is part of that script. However, it's not consistent at all, in certain positions it runs smoothly, but in other positions it's really choppy and sometimes the cup misses it's destination. I think this might be something to with there being too many decimal places in these equations, so perhaps this could use rounding or something?
Note: Pos1 is the position that it should end up,
local Pos1=script.Parent.Parent.Parent.CoffeePos1--Destination of cup
local Time=4--Time it should take to complete
local Distance=(math.abs(Cup.Position.X+Pos1.Position.X))
--Find the distance between the cup and it's destination
local StudsPerSec=(Time/Distance)--Not actually per second
local TimeUp=0
------------
repeat
wait(StudsPerSec)
Cup.CFrame=Cup.CFrame*CFrame.new(StudsPerSec,0,0)
TimeUp=TimeUp+StudsPerSec
until
TimeUp>=Time
--This used to be until the Cup's position equaled the destination, but that didn't work well
do Cup.Position=Pos1.Position--Ensures it is in position
