How to make character face certain direction?

Hello, in the game I’m trying to change players character when certain level is reached. I’ve achieved this with this script:

			local oldPosition = player.Character.PrimaryPart.Position
			local charClone = game:GetService("ServerStorage"):WaitForChild("NewChar"):Clone()
			
			charClone.Name = player.Name
			player.Character = charClone
			charClone.Parent = workspace
			charClone:MoveTo(oldPosition)

Everything seems to be working fine, except that When it’s moved, the cloned character doesn’t face the same direction like the old character. Any suggestions how could I achieve this? Thanks!

Instead of position use cframe

I think the solution is very simple but it may not work, but here is the idea, in the end of the level or whatever player overcome, u can grab the orientation of the player parts and then, before placing clone into workspace, rotate body parts of clone via looping with for _,v in pairs(Clone:GetChildren()) do , so it will be rotated by angles that player has.

You can use SetPrimaryPartCFrame to accomplish that.

Note:
SetPrimaryPartCFrame() is faster than :MoveTo() and it doesn’t check for collisions.

2 Likes

Hey. You could just grab old character’s CFrame instead of position, as mentioned by , @rotbotrotbot , as CFrame corresponds to both position and orientation, not just the position. So generally, if you set new character’s CFrame to the old character’s CFrame, it’s going to be facing the same direction.

Also, you don’t have to, but I think it would be a better idea to first set the clone’s CFrame, then parent it to workspace, and finally set it to be the player’s character.

Code example:
local OldCFrame = player.Character:GetPrimaryPartCFrame()
local CharClone = game:GetService(“ServerStorage”):WaitForChild(“NewChar”):Clone()

CharClone.Name = player.Name
CharClone.CFrame = OldCFrame
CharClone.Parent = workspace
player.Character = CharClone

For some reason this way kills character when setting CFrame. @Xueify way seems to be working smoothly. But thanks for explanation how CFrame works :slight_smile:

1 Like

Seems to be working smoothly. Thanks!

1 Like

No problem! Yeah, I just forgot to include some code at the end… But now that you know how it works it does not matter.

Good luck with your project!

1 Like