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

How to rotate player with teleportation?

Hey, I can't figure out how to rotate a player. I'm trying to make sense of CFrames but I am having trouble with it. Here is my code

if hit.Parent:findFirstChild("Humanoid") then
	local telepoint = Vector3.new(224.152, 61.043, -519.523)
	hit.Parent.HumanoidRootPart.CFrame = CFrame.new(telepoint + Vector3.new(0,3,0))
end

I want the player's orientation to be "0,-168,0" after they teleport, but I'm not sure how to do that since it all seems to have to do with adding and multiplying and stuff like that.

If there is an alternate way to do this without CFrames please let me know but I'm not sure what to do.

Thank you!

1 answer

Hiya!

The easiest way tow can rotate the player's HumanoidRootPart using CFrame.Angles() A quick run-down as to how you add CFrames and Vector3;

  • CFrame uses * (multiply) and / (divide)
  • Vector3 uses + (addition) and - (subtract)

To set the rotation with CFrame.Angles, you have your X, Y and Z variables, and to actually rotate, we need to use math.rad (radians) to get out -168 rotation

-- Assuming 'telepoint' is our desired vector
PlayerCFrame = CFrame.new(telepoint) * CFrame.Angles(0, -math.rad(168), 0)

Our full code would look like this:

if hit.Parent:FindFirstChild("Humanoid") then
    local telepoint = Vector3.new(-36.572, 0.5, -0.269) + Vector3.new(0,3,0)
    hit.Parent.HumanoidRootPart.CFrame = CFrame.new(telepoint) * CFrame.Angles(0, -math.rad(168), 0)
end

Hope this helps! ????

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