I Need Help Lerping Two Parts

  1. What do you want to achieve?
    I want Part1 to go into Part2, then after that, I want them to go to a certain position.

  2. What is the issue?
    Part1 successfully goes inside of Part2, but after that, they do not go to “-3, 16.5, 58”


Here is a video so you can see what I mean.
robloxapp-20220222-1822526_Trim.wmv (353.7 KB)



Here is my code:

local lerpFolder = script.Parent
local part1 = lerpFolder.Part1
local part2 = lerpFolder.Part2

for i = 0, 1, 0.01 do
	wait()
	part1.CFrame = part1.CFrame:Lerp(part2.CFrame, i)
end

local function moveParts()
	for i = 0, 1, 0.01 do
		wait()
		part2.CFrame = part2.CFrame:Lerp(CFrame.new(-3, 16.5, 58), i)
		part1.CFrame = part1.CFrame:Lerp(CFrame.new(-3, 16.5, 58), i)
	end
end

while true do
	wait()
	if part1.CFrame == part2.CFrame then
		moveParts()
		break
	end
end
1 Like

Parts’ CFrames are very rarely equal to each other, even when explicitly stating for them to be equal to each other, probably due to floating point errors.

In your case, the thread is going to yield until the parts are done being interpolated anyway, so checking that the 2 CFrames are equal to each other is redundant, you should be able to call the moveParts function right away without any issues.

2 Likes

Try using Vector.new Vector3 (roblox.com)

The problem is most likely as cody said what you should do is call the move parts function right after the first for loop