How do I CFrame a player 5 studs away from a parts position?

I am trying to make a teleport door that teleports/moves you to a different part of the world, but I am having an issue with the player being teleported inside of the other trigger door making a constant loop of the player teleporting to the entrance and exit at the same time. Here is my code:


for i, doorTouched in pairs(Server.teleportDoor:GetDescendants()) do
	if doorTouched:IsA("Part") then
			doorTouched.Touched:Connect(function(plr)
				local hp = plr.Parent:FindFirstChild("HumanoidRootPart")
				if doorTouched.Name == "Enter" then
					pcall(function()
					hp.CFrame = CFrame.new(doorTouched.Parent:FindFirstChild("Exit").Position)
					end)
				elseif doorTouched.Name == "Exit" then
					pcall(function()
					hp.CFrame = CFrame.new(doorTouched.Parent:FindFirstChild("Enter").Position)	
					end)
				end
			end)
		end
	end
end

I have tried to use a debounce so the player has to wait before being teleported while preventing a loop, but it seems to not do any effect.

2 Likes

To teleport the player a few studs away from the door just multiply the CFrame by a certain amount of studs. (However when you “multiply” a CFrame, it’s considered just adding the CFrames together.)

hp.CFrame = CFrame.new(doorTouched.Parent:FindFirstChild("Exit").Position) * CFrame.new(0, 0, 5)
4 Likes