How would I make a player face at a model?

Hi, so I ran into this problem where I have to teleport my character to the desired Vector3, to play an animation, but the problem is… my character is not facing the model which means I can’t play the animation in the right direction.

I tried searching posts about the same topic but I still am confused :confused:

1 Like

I’m guessing you are teleporting to the CFramed location, but not rotating the character. You need to check how Rotation works.

Also, this isn’t a bug. Bugs are problems with the website or something Roblox related.

2 Likes

Rotate the humanoid root part to face the look vector of the part you are teleporting too. Make sure that part’s front face is correctly facing where the player should be orientated.

function lookAt(chr,target) --assume chr is a character and target is a brick to look towards
	if chr.PrimaryPart then --just make sure the character's HRP has loaded
		local chrPos=chr.PrimaryPart.Position --get the position of the HRP
		local tPos=target.Position --get the position of the target
		local newCF=CFrame.new(chrPos,tPos) --create our CFrame
		chr:SetPrimaryPartCFrame(newCF) --set the HRP's CFrame to our result, thus moving the character!
	end
end

This code from @ChipioIndustries may help. :slight_smile:

3 Likes

for some weird reasons it prints out an error message:

 22:38:32.259 - Players.Grayuu.PlayerGui.LocalScript:10: attempt to index nil with 'PrimaryPart'
1 Like

Please share the code erroring.

1 Like

Here is the script its a local script:

local ClickDetector = game.Workspace.Map.Vent.VentBase.ClickDetector

ClickDetector.MouseClick:Connect(function()
	
	local chr = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
	
	local target = game.Workspace.Target
	
	function lookAt(chr,target) --assume chr is a character and target is a brick to look towards
		if chr.PrimaryPart then --just make sure the character's HRP has loaded
			local chrPos=chr.PrimaryPart.Position --get the position of the HRP
			local tPos=target.Position --get the position of the target
			local newCF=CFrame.new(chrPos,tPos) --create our CFrame
			chr:SetPrimaryPartCFrame(newCF) --set the HRP's CFrame to our result, thus moving the character!
		end
	end
	
	lookAt()
	
	--player.Character:moveTo(Vector3.new(-42, 3, -27.61))
	
	game:GetService("ContextActionService"):BindActionAtPriority(
		"t",
		function()
			return Enum.ContextActionResult.Sink
		end,
		false,
		Enum.ContextActionPriority.High.Value + 1,
		unpack(Enum.PlayerActions:GetEnumItems())
	)


	--game.ReplicatedStorage.RemoteEvent:FireServer(player)
end)

game.ReplicatedStorage.RemoteEvent2.OnClientEvent:Connect(function(isnotMoving) 
	if isnotMoving == false then
		game:GetService("ContextActionService"):UnbindAction("t")
	end
end)
1 Like

The function lookAt has 2 parameters. One is “chr” and one is “target”. You need to give that function this information.

So use something like this:
lookAt(game.Players.LocalPlayer.Character,INSERTPARTHERE)

1 Like

thx it now works I will mark your post as a Solution :happy3:

learned quite a few stuff about rotation with CFrames.

1 Like

Wonderful to hear! Maybe CFrame Angles next hehe

1 Like