How to use CFrames to teleport and rotate player?

I am new to using CFrames and Vectors to move objects, and I understand them well enough but I can’t figure out the rotation aspect.

Here is my base code - (in a server script)

  	local telepoint = Vector3.new(0, 0, 0)
  	local checkpoint2 = workspace.checkpoint2
  	hit.Parent.HumanoidRootPart.CFrame = CFrame.new(telepoint + Vector3.new(0,0,0))

I want to make the Player face a certain way after they teleport to the “telepoint” coordinates. This is the plain code I used before adding rotation. ^^^

Here is my rotation added - (LocalPlayer was stated somewhere in the beginning of the script.)

  	local telepoint = Vector3.new(0, 0, 0)
  	local checkpoint = workspace.checkpoint3
  	local Character = Localplayer.Character
  	Character.HumanoidRootPart.CFrame = CFrame.new(telepoint + Vector3.new(0,0,0)) * >			CFrame.Angles(
  		math.rad(checkpoint.Orientation.X),
  		math.rad(checkpoint.Orientation.Y + 90),
  		math.rad(checkpoint.Orientation.Z)
  	);

And this is what I tried to do to rotate it, which doesn’t work. I have no idea what is wrong, as there are no errors in the script or output. I searched up many solutions but none of them worked, so I was hoping someone here can help me out. Thank you, and sorry if this is a dumb question, again I am new to this.

Try using orientation instead of CFrames. Use orientation and position.

3 Likes

That worked perfectly, thank you!

Sorry for the deleted response, I realized the issue was using Vector instead of C.Frame for the position change.

I tried doing this -

  	local telepoint = Vector3.new(0, 0, 0)
  	if hit.Parent:findFirstChild("Humanoid") then
  		hit.Parent.HumanoidRootPart.CFrame = CFrame.new(telepoint + Vector3.new(0,0,0))
  		hit.Parent.HumanoidRootPart.Orientation = Vector3.new(0,-90,0)
  	end

But that won’t work, I’m not sure why. The Vector seemed to work fine in my test game which was a blank baseplate, but in the actual game it doesn’t work and only C.Frames work. I’m also confused why the vector after the c.frame isn’t working.

Try this?

CFrame.new(telepoint) * CFrame.new(0,0,0)

I’m not really understanding the problem your facing but I hope this helps. :slight_smile:

Would I set the CFrame.New coordinates to the orientation I want?

Please set my comment as the solution so other people knowns this is the solution.

I did mark it as a solution until I realized it wasn’t working for some reason.

I think i know another way tho. U can set the cframe of every single part in the character. Like using an in pairs loop.

You can try:

local position = Vector3.new(x, y, z) -- Choose position
local lookPosition = Vector3.new(0, 0, 0) -- the player must look at the center of the world

hit.Parent.HumanoidRootPart.CFrame = CFrame.new(position, lookPosition)

https://developer.roblox.com/en-us/articles/Understanding-CFrame