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

how do i make a teleport work properly?

script:

script.Parent.MouseButton1Click:Connect(function()
	game.Players.LocalPlayer.Character.LowerTorso.Position = Vector3.new(-144.54, 5.236, 91.32)
end)

no errors my character doesn't teleport and it moves random parts of my characters body

1 answer

✓ Accepted answer

When teleporting/moving a character to another place, it's always best to use the HumanoidRootPart instead of moving one by one. On the other hand, you can also use the function :SetPrimaryPartCFrame which sets a model's CFrame to whatever is indicated in the parentheses.

I'll indicate 2 examples below and it's up to you to pick your prefered method.

Option #1

script.Parent.MouseButton1Click:Connect(function()
    game.Players.LocalPlayer.Character.HumanoidRootPart.Position = Vector3.new(-144.54, 5.236, 91.32)
end)

Option #2

script.Parent.MouseButton1Click:Connect(function()
game.Players.LocalPlayer.Character:SetPrimaryPartCFrame(CFrame.new(Vector3.new(-144.54, 5.236, 91.32)))
end)

{Option #3 (What I usually do)}

script.Parent.MouseButton1Click:Connect(function()
    game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(-144.54, 5.236, 91.32))
end)

Here is some documentation on it: https://developer.roblox.com/en-us/api-reference/function/Model/SetPrimaryPartCFrame

Hope this has helped you ;)

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