How to make a player face certain part

Hello this is my first post and i’m trying to make a player face a certain part because i want to attach the player to the part like if it was standing on the part but sometimes due to the velocity the player gets when approaching to the part the rotation of the player gets weird.

I’ve been trying to change the rotation of the HumanoidRootPart in different ways but sadly i couldn’t figure it out.

Hi there and welcome to the forums! :smile:

Well, models as we know don’t have properties that Parts do, however, Roblox has thankfully made a method called :SetPrimaryPartCFrame() that we can use to move Models around.

You know how we can use CFrame.new(part1.Position, part2.Position) to make a part face another?

Well, we can use the PrimaryPart property that’s inside the player model to do just that.

You could write something along the lines of this, server or client side (be sure to wait for the player to join the server & to have its character model loaded in workspace. To do this you could just utilize the :CharacterLoaded() method):

local playerService = game:GetService("Players")

local YOUR_PLAYER_NAME = "Player1"
local PART_NAME = "Part"

local yourPlr = playerService:FindFirstChild(YOUR_PLAYER_NAME)
local findPart = game.Workspace:FindFirstChild(PART_NAME)

if yourPlr and findPart then

	if yourPlr.Character.PrimaryPart then
		local cfr = CFrame.new(
			yourPlr.Character.PrimaryPart.Position,
			findPart.Position)

		yourPlr.Character:SetPrimaryPartCFrame(cfr)
	end
end
3 Likes

Hello, thank you for your answer!
I tryied that before and it gave me weird results too in the rotation of the HumanoidRootPart as you can see in the video.
Sometimes it works and some does not.
Part of the code:
HRP.Anchored = true
local cfr = CFrame.new(
character.PrimaryPart.Position,
mouse.Target.Position)

							character:SetPrimaryPartCFrame(cfr)

The mouse.Target is the part where the player is aiming at.
Video of the problem:
https://streamable.com/s5qtwb