I have these Railroad tracks! They're pretty long and pretty curvy at the same time! Download the Video

THE CODE:

local RunService = game:GetService("RunService")
local Speed = .01
local model = script.Parent

function GetTime(Distance, Speed)
	-- Time = Distance / Speed
	local Time = Distance / Speed
	return Time
end

local Points = {}
local function movemodel()
	for i = 0,1,Speed do
		wait()
		if not model.PrimaryPart then
			break
		end		
		model:SetPrimaryPartCFrame(Points[1].CFrame:Lerp(Points[2].CFrame,i))
	end

	for i = 0,1,Speed do
		wait()
		if not model.PrimaryPart then
			break
		end		
		model:SetPrimaryPartCFrame(Points[2].CFrame:Lerp(Points[3].CFrame,i))
	end
end

movemodel()

However, when it takes a few turns with the other train cars, they won't maintain the same speed when turning and moving straight. Causing them to collide and making it weird to move!

3 comments

0

Can you please use the code blocks properly? Only code goes into them and the tildes are supposed to be on their own lines 

0

As for what I can see there right now, you do have the right idea using CFrame:Lerp()

0

EDIT: Added Code Blocks / Embedded Link