Is it possible to make a part using "CFrame:Lerp()" to move keep a constant speed?

Hello, I got 3 parts (the start part, the middle part and the end part)
I’m trying to make the start part move to the middle part then without stoping or slowing down move to the end part using the “CFrame:Lerp()”

the server script I’m using for this is in the StartPart:

local StartPart = workspace.StartPart
local MiddlePart = workspace.MiddlePart
local Endpart = workspace.EndPart

--Move to MiddlePart
for i = 0,1,0.01 do
	wait()
	StartPart.CFrame = StartPart.CFrame:Lerp(MiddlePart.CFrame,i)
end

--Move to EndPart
for i = 0,1,0.01 do
	wait()
	StartPart.CFrame = StartPart.CFrame:Lerp(Endpart.CFrame,i)
end

but when I run the game the moving part (StartPart) slows down and briefly stops at the middle part then moves to the end part:

so is there a way to make the moving part keep a constant speed?

Try this:

--//Services
local TweenService = game:GetService("TweenService")

--//Variables
local StartPart = workspace.StartPart
local MiddlePart = workspace.MiddlePart
local Endpart = workspace.EndPart

--//Functions
local movementTween1 = TweenService:Create(StartPart, TweenInfo.new(2, Enum.EasingStyle.Linear), {CFrame = MiddlePart.CFrame})
movementTween1:Play()
movementTween1.Completed:Wait()

local movementTween2 = TweenService:Create(StartPart, TweenInfo.new(2, Enum.EasingStyle.Linear), {CFrame = Endpart.CFrame})
movementTween2:Play()
movementTween2.Completed:Wait()
1 Like

I know that I could use TweenService for this but I really need it to be using “CFrame:Lerp()”

would this work?

for i = 0,2,0.01 do
	wait()
	if i >= 1 then
		StartPart.CFrame = StartPart.CFrame:Lerp(Endpart.CFrame,(i - 1))
	else
		StartPart.CFrame = StartPart.CFrame:Lerp(MiddlePart.CFrame,i)
	end
end
1 Like

I tried it and it still does the same thing

I’ll try to make a script for lerp but I’m just wondering the reason why you wouldn’t use TweenService. If it’s because of lag concerns, you can just use a remote event.

Try this:

local StartPart = workspace.StartPart
local MiddlePart = workspace.MiddlePart
local Endpart = workspace.EndPart

--Move to MiddlePart
for i = 0, 1, 0.01 do
	if i >= 0.3 then
		StartPart.CFrame = MiddlePart.CFrame
		
		break
	end
	
	task.wait()
	StartPart.CFrame = StartPart.CFrame:Lerp(MiddlePart.CFrame, i)
end

--Move to EndPart
for i = 0, 1, 0.01 do
	if i >= 0.3 then
		StartPart.CFrame = Endpart.CFrame
		
		break
	end
	
	task.wait()
	StartPart.CFrame = StartPart.CFrame:Lerp(Endpart.CFrame, i)
end
1 Like

mmm well your script does make it stop less but you see I need it to be at a speed that isn’t that fast
actually I’m planing to make a train that will move using parts positioned along the rails then use this local script to make the player follow the moving train platform if he is standing on it:

local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local RunService = game:GetService('RunService')

local LastTrainCFrame

local Function
local Function2


Function = RunService.Heartbeat:Connect(function()

	--------------------------------------------------------------- CHECK PLATFORM BELOW

	local RootPart = player.Character.LowerTorso

	local Ignore = player.Character

	local ray = Ray.new(RootPart.CFrame.p,Vector3.new(0,-50,0))

	local Hit, Position, Normal, Material = workspace:FindPartOnRay(ray,Ignore)

	if Hit and Hit.Name == "TrainPlateform" then 

		--------------------------------------------------------------- MOVE PLAYER TO NEW POSITON FROM OLD POSITION

		local Train = Hit
		if LastTrainCFrame == nil then -- If no LastTrainCFrame exists, make one!
			LastTrainCFrame = Train.CFrame -- This is updated later.
		end
		local TrainCF = Train.CFrame 

		local Rel = TrainCF * LastTrainCFrame:inverse()

		LastTrainCFrame = Train.CFrame -- Updated here.

		RootPart.CFrame = Rel * RootPart.CFrame -- Set the player's CFrame
		print("set")

	else
		LastTrainCFrame = nil -- Clear the value when the player gets off.

	end

	Function2 = player.Character.Humanoid.Died:Connect(function()
		Function:Disconnect() -- Stop memory leaks
		Function2:Disconnect() -- Stop memory leaks
	end)

end)

I’ve already tried to make the train move using TweenService and it worked well but the only problem was that the local script for some reason kept moving the player to the front when the train moved using tween service then when I made it use the CFrame:Lerp() the local script worked perfectly but the train stoped everytime it got to a part on the rails…

I did some testing and research. Try this out.

local StartPart = workspace.Part
local MiddlePart =  workspace.MiddlePart
local Endpart = workspace.EndPart

local sCFrame = StartPart.CFrame

for i = 0,2,0.01 do
	wait()
	if i >= 1 then
		StartPart.CFrame = MiddlePart.CFrame:Lerp(Endpart.CFrame,(i - 1))
	else
		StartPart.CFrame = sCFrame:Lerp(MiddlePart.CFrame,i)
	end
end
1 Like

Try this:

local StartPart = workspace.StartPart
local MiddlePart = workspace.MiddlePart
local Endpart = workspace.EndPart

task.wait(3)

--Move to MiddlePart
for i = 0, 1, 0.01 do
	if i >= 0.3 then
		StartPart.CFrame = MiddlePart.CFrame
		
		break
	end
	
	task.wait(0.02)
	StartPart.CFrame = StartPart.CFrame:Lerp(MiddlePart.CFrame, i)
end

--Move to EndPart
for i = 0, 1, 0.01 do
	if i >= 0.3 then
		StartPart.CFrame = Endpart.CFrame
		
		break
	end
		
	task.wait(0.02)
	StartPart.CFrame = StartPart.CFrame:Lerp(Endpart.CFrame, i)
end

Change the task.wait(n) and the i >= n to change the speed.

1 Like

Yes Finally! this works,Thanks!

1 Like

still didn’t work but thanks for helping!!