I have a script that moves parts around an elevator. To smoothly move a range of parts, I have them all in a single model to make it easy to script them. I thought the issue was the while loop, but it turns out that :MoveTo() was not updating the model’s position for a while after the button was activated. After a few seconds, the model teleports to where it should have been and continues normally.
local buttonPressed = false
game:GetService("RunService").Heartbeat:Connect(function()
local parts = workspace:GetPartBoundsInRadius(camera.CFrame.Position, 1, params)
local inAnyPart = #parts ~= 0
if inAnyPart then
if not buttonPressed then
print("touching")
buttonPressed = true
local t0 = tick()
while everythingElse:GetPivot().Position.Y > finalPos.Y do
print("hihihih")
local curr = (tick() - t0) * elevatorSpeed
everythingElse:MoveTo(originalPos + Vector3.new(0, -curr, 0))
task.wait()
end
end
end
end)
I ended up solving it by using everythingElse:PivotTo(CFrame.new() + Vector3.new(0, -curr, 0)) instead. I thought PivotTo() and MoveTo() were the model equivalent of .CFrame and .Position for BaseParts, but it seems the two work differently than CFrame and CFrame.Positon.