Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this script not work in certain positions?

Asked by
SuperFryX 130
8 years ago

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

Answer this question