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:
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
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)