Rotating the player to face the same direction as a Part's front face

  1. What do you want to achieve?
    I’d like the player, when teleported to face the same direction as the front of the part.

  2. What is the issue?
    I’m not really sure how I would do this. I’ve tried some solutions, more below.

  3. What solutions have you tried so far?
    I’ve looked through some other topics, but haven’t found anything relating to this (if you know of any a link to it would be great). I’ve already tried using CFrame, but this doesn’t work for whatever reason.

HRP.CFrame = workspace.Checkpoints[tostring(ServerData[Player].leaderstats.Level)].CFrame`

For context, ServerData[Player].leaderstats.Level is an Integer, I’m finding the part perfectly fine, but the orientation isn’t working properly.

Any help is much appreciated :slightly_smiling_face:

You may need to use RunService’s Heartbeat event, the CFrame will only change once from your script so you’ll need to put it through some loop to keep its consistent Orientation:

local RunService = game:GetService("RunService")

RunService.Heartbeat:Connect(function()
    HRP.CFrame = workspace.Checkpoints[tostring(ServerData[Player].leaderstats.Level)].CFrame
end)

Try this and see if anything changes?

Utilice CFrame.lookAt () and Character:SetPrimaryPartCFrame():

local D = workspace.Checkpoints[tostring(ServerData[Player].leaderstats.Level)]
local Look = D.CFrame.LookVector * 2
Character:SetPrimaryPartCFrame(CFrame.lookAt(D.Position,Look))

Remove this when my other message is deleted

I’d use CFrame.

local HumanoidRootPart = {...}

HumanoidRootPart.CFrame = CFrame.new(Part.Position + Vector3.new(0, 3, 0))

POINTS

  • I added Vector3.new() so the player don’t spawn inside of the Part.
  • Change “{…}” for the HumanoidRootPart location, using Player instance.

The script only executes on the Player.CharacterAdded event, won’t this loop teleport them?

I’m already using CFrame though, what’s the difference?

Can you show us your script, please?

Also, I’ve made some changes in the script;

--// Variables //--
local Checkpoints = game.Workspace:WaitForChild("Checkpoints")

--// Functions //--
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		
		local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
		if HumanoidRootPart then
			if Checkpoints:FindFirstChild(tostring(ServerData[Player].leaderstats.Level.Value)) then
				
				local Part = Checkpoints:WaitForChild(tostring(ServerData[Player].leaderstats.Level.Value))
				HumanoidRootPart.CFrame = CFrame.new(Part.Position + Vector3.new(0, 3, 0))
			end
		end
	end)
end)
Player.CharacterAdded:Connect(function(Character)
		local HRP = Character:WaitForChild("HumanoidRootPart", 5)
		HRP:GetPropertyChangedSignal("CFrame"):Wait()
		HRP.CFrame = workspace.Checkpoints[tostring(ServerData[Player].leaderstats.Level)].CFrame
		
		Character.Humanoid.Died:Connect(function()
			wait(1.5)
			Player:LoadCharacter()
		end)

This gives about all of the context. Essentially when the Player’s character is added it will set their position and load their character.

Alright, try using the script that I sent above.

That is not needed, I still have the same problem. It won’t rotate the player correctly.

Whoops, maybe try this?

local RunService = game:GetService("RunService")
local Part = workspace.Checkpoints[tostring(ServerData[Player].leaderstats.Level)]
HRP.CFrame = Part.CFrame

RunService.Heartbeat:Connect(function()
    HRP.CFrame = CFrame.new(HRP.Position, Part.Position)
end)

Try using lookVector. That may works fine.

I’ve found a solution after scrolling through forum posts and lots of head scratching to find out what the problem was.

It was as simple as to just add a wait() in there, to give the character time to load.

function TeleportPlayer(Player)
	Player.Character.HumanoidRootPart.CFrame = workspace.Checkpoints[DataModule:RequestData(Player, "Level")].CFrame
end
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		wait(3)
		TeleportPlayer(Player)
	end)
	
	Player:LoadCharacter()
end)

I also tidied everything up into ModuleScripts, this doesn’t actually effect anything other than the code looking slightly better. DataModule:RequestData(Player, "Level") is the same as ServerData[Player].leaderstats.Level.

Thanks for everyone’s input on this :slightly_smiling_face: