Teleport not seamless, wrong CFrame

I am trying to create an infinite corridor.
The way I do this, is I have 3 parts inside the corridor, tp1, tp2, and tpTarget. tpTarget is in between tp1 and tp2. When player touches tp1 or tp2, they are teleported to tpTarget.
I want the teleportation to be seamless, and to do this, I made the corridor repetitive (the lights seem positioned at random, but they are actually divided into sections that repeat). Everything (tp1, tp2, and tp target), are placed in neighboring section starts, basically at the beginning of each repeating section of the corridor.
I’ve checked their positioning, it is exactly the way it is supposed to be, correct down to 0.00000001 studs. Their sizes and orientation are the same.
When touching tp1, or tp2, I get HumanoidRootPart relative CFrame to that part, then convert it to a relative of tpTarget, and teleport.

Here’s the script.

local tp = script.Parent:WaitForChild("Tp")
local tp2 = script.Parent:WaitForChild("Tp2")
local tpTarget = script.Parent:WaitForChild("TpTarget")

tp.Touched:Connect(function(hit)
	if hit and hit.Name == "HumanoidRootPart" and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		local relative = tp.CFrame:ToObjectSpace(hit.CFrame)
		hit.CFrame = tpTarget.CFrame:ToWorldSpace(relative)
	end
end)

tp2.Touched:Connect(function(hit)
	if hit and hit.Name == "HumanoidRootPart" and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		local relative = tp2.CFrame:ToObjectSpace(hit.CFrame)
		hit.CFrame = tpTarget.CFrame:ToWorldSpace(relative)
	end
end)

But here’s a video, that clearly shows teleportation is not seamless, it appears to be teleporting very slightly behind where it should, and I don’t know why.

You can see the teleporting at 0:12, 0:28, and the most obvious at 0:52.

Why is this happening and how to fix it?

1 Like

Make sure you are handling it on the client so it’s not held back by networking lag