Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to CFrame Lerp a model?

I have some code, which makes a object follow a path of parts. This is for a rollercoaster. I was wondering if anyone would able to help me so that:

  1. It moves a model instead of one part
  2. Anyway to make it more efficient
  3. Is there anyway to get all the track parts without having to manually write every one

Thanks!

local p1 = script.Parent:WaitForChild("Track1")
local p2 = script.Parent:WaitForChild("Track2")
local p3 = script.Parent:WaitForChild("Track3")
local p4 = script.Parent:WaitForChild("Track4")
local p5 = script.Parent:WaitForChild("Track5")
local rp = script.Parent.CarFront


while wait() do
	for i = 0,1,.05 do 
		rp.CFrame = p1.CFrame:lerp(p2.CFrame,i)
		wait(0.0001)
	end
	for i = 0,1,.05 do 
		rp.CFrame = p2.CFrame:lerp(p3.CFrame,i)
		wait(0.0001)
	end
	for i = 0,1,.05 do 
		rp.CFrame = p3.CFrame:lerp(p4.CFrame,i)
		wait(0.0001)
	end
	for i = 0,1,.05 do 
		rp.CFrame = p4.CFrame:lerp(p5.CFrame,i)
		wait(0.0001)
	end
	for i = 0,1,.05 do 
		rp.CFrame = p5.CFrame:lerp(p1.CFrame,i)
		wait(0.0001)
	end
end

1 answer

use :MoveTo.

This function will move an entire model to the block's position, so you may have to create a block at the designated position, don't use:

track:MoveTo(part.CFrame)

It is wrong, use:

track:MoveTo(part.Position)

This discussion is preserved as it was. New answers, comments, and votes are closed.