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

How would I make a player face a certain direction after being teleported?

I'm making an elevator script that teleports players and I was wondering how I would make the player face the directing they were facing before they were teleported. The method I use for teleporting the player looks like this:

p.Character:MoveTo(Vector3.new(-491.607, -102.069, 27.55))

If it helps, this is what my entire script looks like:

Button1.ClickDetector.MouseClick:Connect(function()
	ButtonClicked() -- function for closing the door
	if script.Parent.InElevator.Value == true then
		Button1.ClickDetector.MaxActivationDistance = 0
		wait(1.1)
		script.Parent.Door.Moving:Play()
		wait(7)
		script.Parent.InElevator.Value = false
		script.Parent.Parent.Parent.Parent.Elevator.ElevatorDoor.ScriptedComponents.Door.Beep:Play()
		wait(.8)
		
		p.Character:MoveTo(Vector3.new(-491.607, -102.069, 27.55))
		Debounce = false
		Button1.ClickDetector.MaxActivationDistance = 4
		
		script.Parent.Parent.Parent.Parent.Elevator.ElevatorDoor.ScriptedComponents.ComingOut.Value = true
		wait(2)
		script.Parent.Parent.Parent.Parent.Elevator.ElevatorDoor.ScriptedComponents.ComingOut.Value = false
	end
end)

Any help is appreciated!

5 comments

0

I recommend using CFrame as that also includes a part's Orientation (Rotation), so if you teleport them there, their front body will be facing the direction the front of the part is.

0

So would I use SetPrimaryPartCFrame?

0

Correct, use it!

0

Ah, I'm in idiot - I actually tried that but it didn't seem to change anything, it was because I was testing a different elevator than the one I was editing, I'll try it now

0

*an

1 answer

By setting the Character's PrimaryPart's CFrame after teleporting, you can rotate them.

CFrame accepts many Vector3s, but the first (and most relevant to you) two are Position and LookVector.

CFrame.new(Position, LookVector);

Position would be the actual position (as a Vector3), and LookVector is where it would face.

Here's an example:

-- Teleport Part1 in workspace to Part2, then make it rotate towards Part3
workspace.Part1.CFrame = CFrame.new(workspace.Part2.Position, workspace.Part3.Position);

Models have a method called :SetPrimaryPartCFrame(CFrame);, so keep that in mind while working on this.

Learn more about SetPrimaryPartCFrame here

Learn more about CFraming here

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