So I am moving a model left + right with setprimarypartcframe, but how would I move it back to where it started?
How I'm moving it:
local function _left() for i = 0,1,.001 do goalie:SetPrimaryPartCFrame(goalie:GetPrimaryPartCFrame() * CFrame.new(-i,0,0)) wait() if (goalie.Stick.Position - bound.Boundary2.Position).magnitude <= x then return end end end local function _right() for i = 0,1,.001 do goalie:SetPrimaryPartCFrame(goalie:GetPrimaryPartCFrame() * CFrame.new(i,0,0)) wait() if (goalie.Stick.Position - bound.Boundary3.Position).magnitude <= x then return end end end
You should record somewhere the initial/default position, then set the CFrame to that position.
It seems you are using a loop and wait()
to show a sort of animation, and I'd highly recommend using TweenService which is much simpler in my opinion. If you do use TweenService, all you need to keep track of is the final positions and it will automatically animate the object to that position.
Continuing with your method however, you can create a function _returnToDefaultPosition()
that would use a while
loop rather than a for
loop, and moves the model a little bit every loop until you reach your default position.