How do I make the player face the part I want them to look at?

so if I face the valve, the animation plays correctly, but if I face the side of the valve, the player won’t face the valve, but the direction he was looking at.

Video example:

Script which makes the player face that way:

function Hold(player)
	local HRP 	    = player.Character:WaitForChild("HumanoidRootPart")
	local hum 	    = player.Character:WaitForChild("Humanoid")
	local lookatp   = script.Parent.Parent.LookAtPart
	HRP.CFrame 	    = CFrame.lookAt(HRP.Position, Vector3.new(lookatp.Position.X, lookatp.Position.Y, lookatp.Position.Z))

	local valveAnim = hum.Animator:LoadAnimation(animation)
	
	if playerHolding then return end
	playerHolding   = player
	valveAnim:Play()
	wait()
	
	HRP.CFrame      = CFrame.lookAt(HRP.Position, Vector3.new(lookatp.Position.X, lookatp.Position.Y, lookatp.Position.Z))
	hum.AutoRotate  = false
	HRP.Position    = Root.Position
	HRP.Anchored    = true
	
	stopanim.Event:Connect(function(player)
		valveAnim:Stop()
	end)
	
	repeat
		Valve.CFrame = Valve.CFrame*CFrame.Angles(-0.1, 0, 0)
		task.wait(1/40)
	until not playerHolding 
end
1 Like

You can usually make things look at another object by doing:
MainPart.CFrame = CFrame.new(MainPart.Position, PartToLookAt.Position)
and then using * CFrame.Angles() if you need to fix rotation.

1 Like

You should use CFrame.LookAt for this

I am using CFrame.Lookat though

	HRP.CFrame 	    = CFrame.lookAt(HRP.Position, Vector3.new(lookatp.Position.X, lookatp.Position.Y, lookatp.Position.Z))

In case I wasn’t clear, if the player is facing the valve, the character stays correctly, yet when the player is facing the sides or the back of the valve, they won’t face the valve properly when playing the animation