Player teleportation: what should I be using?

Humanoid:MoveTo(), SetPrimaryPartCFrame, Pivot Points… I have so many options, which is the best as of now for player teleportation?

:MoveTo just makes the character walk to a point. I’d recommend you do:
Character.HumanoidRootPart.Position = positionhere

Humanoid:MoveTo(Vector3) causes the humanoid to attempt to walk to a point.
SetPrimaryPartCFrame has been deprecated, so I’d recommend you don’t use that.

The best option is probably PVInstance:PivotTo(CFrame). It’s similar to SetPrimaryPartCFrame, just relative to the pivot (Probably isn’t the only difference, read more on it here).

I wouldn’t recommend using PrimaryPart.Position (or HumanoidRootPart.Position),
since all it does it move it to that position (which typically works, but it can cause problems with other things like ragdoll systems that PivotTo works for, since it moves the entire model rather than a single object)

To teleport a player, just use this:

Character.HumanoidRootPart.CFrame = cframe

Here is an example code:

-- Example Code -- 

local ClickPart = workspace.ClickPart -- part,which will be clicked
local Part = workspace.Part -- part, to which the player will teleport

local ClickDetector = ClickPart:WaitForChild("ClickDetector") -- getting clickDetector

function onClicked(player)
	local character = player.Character or player.CharacterAdded:Wait() -- getting character
	local humanoidRootPart = character:WaitForChild("HumanoidRootPart") -- getting HumanoidRootPart
	if humanoidRootPart then -- checking if humanoidRootPart existed
		humanoidRootPart.CFrame = Part.CFrame + Vector3.new(0, 3, 0) -- Teleporting player
	end
end

ClickDetector.MouseClick:Connect(onClicked) -- connecting event MouseClick with function
1 Like

I personally prefer SetPrimaryPartCFrame over Humanoid:MoveTo(). Although considering SetPrimaryPartCFrame is deprecated, pivot points may be a better solution(I haven’t tested them yet).

You really don’t want to this, since it can break other systems that make the connections between the character limbs non-rigid. You should use :PivotTo() instead, since it moves the model, rather than a single part of it.

2 Likes

how does :PivotTo work, is it just like

game.Workspace.Part:PivotTo(vector3position)

or can i use :PivotTo on a model and not just a part? or only models?

Using CFrames would be the easiest and best option, I’ve made some abilities for games that require teleporting from point a to point b and I’ve found that setting the humanoidRootPart’s CFrame to wherever you need your player to be is the best way of doing it. I would refrain from using position to do it since it only moves the HumanoidRootPart and not the player.

PivotTo() works for both Models and BaseParts (Basically every type of part). Either works, but I typically use it on the model since you don’t have to get a part to pivot, you just move the model (Using Player.Character instead of finding a part in their character to move).

Using CFrame still only moves the HumanoidRootPart, CFrame just includes rotational data.

:PivotTo can be used on basePart(Part and meshPart) or on model. All assumption this function is to moving full models instead one part from model. In short relies on moving Part or Model and all their descendants together. (API Documentation, :PivotTo)

If we will use Part.CFrame then only we will move part.
If we will use Model:PivotTo(cframe) then we will move model with all their descendants.

Basic Code:

local model = workspace.Model -- Model in workspace 
local cf = CFrame.new(0, 10, 0) -- this must be cframe 
model:PivotTo(cf) -- moving model 10 studs up
1 Like

BaseParts aren’t just Parts and MeshParts, there’s many more variants it covers.

1 Like

its better to use Character.HumanoidRootPart.CFrame = cframehere as teleporting them that way breaks ProximityPrompts