Fix player rotation when spawning players by CFrame

I’m currently having an issue when trying to spawn players based on ‘Stages’. The player will always spawn facing the same direction. What I’m aiming to do is spawn the player whichever direction X face is facing on the part. Is this possible?

Code:
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new(“Folder”, Player)
leaderstats.Name = “leaderstats”

local Checkpoint = Instance.new("IntValue", leaderstats)
Checkpoint.Name = "Checkpoint"
Checkpoint.Value = 1

Player.CharacterAdded:Connect(function(Character)
	repeat wait() until Player.Character ~= nil
	local checkpoint = workspace.Checkpoints:FindFirstChild(Checkpoint.Value)
	Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(checkpoint.Position + Vector3.new(0,2,0))
end)

end)

1 Like

The solution is actually quite simple!

CFrames can take multiple parameters but the ones you want to focus on the most are CFrame.new(Position, LookVector).

LookVector should be the position of the part you want players to look at and Position should be the spawn point you want players to spawn at.

Hope this helps! :slight_smile:

1 Like

Could you provide more of an explanation to this? Some may not understand. Thanks :slight_smile:

1 Like

Actually CFrame.lookAt(Position,PositionToLookAt) is better. Position needs to be the Character’s PrimaryPart Position and PositionToLookAt needs to be the next stage’s spawn position. With the result set Character:SetPrimaryPartCFrame(Result)

1 Like

No you just need to take the Part’s CFrame. CFrame includes position and orientation.

local Checkpoint = Instance.new("IntValue", leaderstats)
Checkpoint.Name = "Checkpoint"
Checkpoint.Value = 1

Player.CharacterAdded:Connect(function(Character)
	repeat wait() until Player.Character ~= nil
	local checkpoint = workspace.Checkpoints:FindFirstChild(Checkpoint.Value)
	Character:WaitForChild("HumanoidRootPart").CFrame = checkpoint.CFrame + CFrame.new(0,2,0)
end)