Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is the best way to teleport? Has the least bugs

There are many ways like using a Body Position(false teleporting), or Torso Positioning with CFrame. But what is the best way to teleport which causes the least bugs.

Example one: This uses CFrame

local debounce = true
local Tele2 = game.workspace.ExampleVariablePart

script.Parent.Touched:connect(function(hit)
	if debounce == true and hit.Parent:FindFirstChild("Humanoid") then
		debounce = false
		hit.Parent.Torso.CFrame = Tele2.CFrame
		wait(1)
		debounce = true
		
	end
end)

Example two: This uses a bodyposition

local debounce = true

script.Parent.Touched:connect(function(hit)
	if debounce == true and hit.Parent:FindFirstChild("Humanoid") then
		debounce = false
		local BP = Instance.new("BodyPosition")
		BP.Parent = hit.Parent:FindFirstChild("HumanoidRootPart")
		BP.Position = Vector3.new(0,0,0) -- example
		wait(1)
		debounce = true

	end
end)

The answer may not even be one of these examples but I just need the best way

2 answers

✓ Accepted answer

If all you need is to set the Vector3 position of the character,

local teleportTo = Vector3.new(100, 10, 100)
character:MoveTo(teleportTo)

works just fine.

However, if you need to make sure the character is rotated a certain way, you must use CFrame on one of the character's body parts. To easily ensure compatibility between R6 and R15 rig types, just use the HumanoidRootPart, which exists in both rig types.

For example, if I want to make sure the character is facing the center of the map after being teleported...

local teleportTo = Vector3.new(100, 10, 100)
local lookAt = Vector3.new(0, 0, 0)
character.HumanoidRootPart.CFrame = CFrame.new(teleportTo, lookAt)

This discussion is preserved as it was. New answers, comments, and votes are closed.