I have a car model in my game that comes from a tunnel and enters another in a loop.
At first, I wanted to have it move the entire the way, even when you can’t see it, but then I found out every time it does a loop it goes 0.001 studs to the right, a minor change but noticeable in the long run.
So now I’m trying to have it teleport when it enters the tunnel but I can’t figure out how.
I have a main part welded to the other parts in the model that moves the car.
while true do
wait()
for i = 1,32 do
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,0,-4) --car goes forward
wait()
end
for i = 1,10 do
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,0,-3)
wait()
script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0,math.rad(9),0) * CFrame.new(0,0,4) --car turns left
wait()
end
for i = 1,300 do
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(-4,0,0) --car goes forwardLONG
wait()
end
for i = 1,10 do
script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0,math.rad(-9),0) * CFrame.new(0,-1,0) --car goes down and turns right
wait()
end
end
You can set a PrimaryPart to the model and use either :SetPrimaryPartCFrame( CFRAME ) or :MoveTo( POISITION ) to teleport the model after. (I recommend using SetPrimaryPartCFrame so that the model does not collide with others)
Since you said you have one main part welded the others, you can simply make the main part the PrimaryPart.
Mh, Same as before.
Does it matter where I place it?
I placed it right after the “car goes down” part and I placed the local variable right at the start.
You can print the CFrame of the main part right after you teleport it, to see if it’s moving accordingly. Maybe the loop you made with the while true do is overwriting the CFrame movement. If you haven’t already, you should enable Output to rule out any technical errors.