Model teleports to random places when using SetPrimaryPartCFrame

my goal is to make the model move downwards after a tween that closes the door. i’ve tried other ways to accomplish this, like using MoveTo, but had no success doing so. this is the code:

whenever i run the code it makes the model teleport to a random location. sometimes to the very top of the workspace, sometimes to the very bottom, and sometimes to the very middle. i followed a tutorial to do this, maybe its outdated? if it is, is there a newer way to do this?

the model teleporting to the top of the workspace after i run the script:

Firstly, that tutorial is outdated. Use SetPrimaryPartCFrame() is deprecated; use GetPivot() and PivotTo() instead.

Secondly, your logic is going to move the model upwards. The variable i in your for loop is increasing by 0.001 per step, so your model will move upwards one stud instead of downwards like you have intended. Also, there is no need to adjust by i; just move the model down by a constant value i times.

Finally, are you wanting to move the model down instantly? Your for loop has no wait call (use task.wait() instead btw), so it will execute instantly.

Assuming you want a delay, do this instead:

for i = 1, 0, .001 do
  local pivot = tube:GetPivot()
  tube:PivotTo(pivot *, -0.01, 0)) -- adjust -0.01 for movement

If you don’t want a delay, just do this:

tube:PivotTo(tube:GetPivot() *, -1, 0)) -- adjust -1 for movement
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.