Object moving outside model

Hello! I want to make the player teleport into the elevator, but the player sometimes teleports outside the model when I use it. Here is my closet script:

-- isPlayerHidingHere is a varible set inside the script
isPlayerHidingHere = not isPlayerHidingHere
script.Parent.Interaction.ProximityPrompt.Enabled = false

if isPlayerHidingHere then
	player.Character.HumanoidRootPart.CFrame = CFrame.new(player.Character.HumanoidRootPart.CFrame.Position) * CFrame.Angles(0, script.Parent.TeleportPart.Orientation.Y, 0)
	wait(.1)
	player.Character:MoveTo(script.Parent.TeleportPart.Position)
	player.Character.Humanoid.WalkSpeed = 0
	player.data.isHiding.Value = true
	playerThatIsHiding = player
else
	player.Character:MoveTo(script.Parent.ExitPart.Position)
	player.Character.Humanoid.WalkSpeed = 14
	player.data.isHiding.Value = false
	playerThatIsHiding = nil
end

task.wait(1)

script.Parent.Interaction.ProximityPrompt.Enabled = true

And here is what is happening:

Don’t use :MoveTo. It is not guaranteed to move the Model to the exact specified location because it will try to avoid collisions.
Use Model:PivotTo instead.

1 Like

How do I achieve this? I’m assuming something like this: player.Character:PivotTo(script.Parent.TeleportPart.CFrame)

Yes. You literally just replace MoveTo with PivotTo. It still takes a CFrame.

Works perfectly! Thanks a lot!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.