Rotating a part to face character?

So I am working on an object placement system. Right now it works alright and I can get it to move the part to where the mouse is but if I add the line that tries to rotate the part I get an error. So here is the relevant code:

local hover = mouse.Hit
local x, y ,z = CFrame.fromEulerAnglesXYZ(chr.Head.Position.x, chr.Head.Position.y, chr.Head.Position.z)
mc:SetPrimaryPartCFrame(, hover.y, hover.z))
mc:SetPrimaryPartCFrame(CFrame.Angles(x, y ,z))

Chr is a variable that is set to the character. Then right here is the error that comes up:

[Players.CrispyBrix.PlayerGui.Menus.BuildBox.WoodWall.CraftBut.LocalScript:25: bad argument #3 to ‘Angles’ (number expected, got nil)

This is in a localscript in a GUI in the player. Its local because I don’t want others seeing what is being placed until it is placed. Basically my question is why is the characters body positions returning nil? Is it a problem with my code or would it be something unrelated like I have the variable set to the wrong place?

local Firstpos =, hover.y, hover.z)
local PositionYouWantToLookAt = root.CFrame.p  --I've honestly never noticed a difference, between the CFrame and Position in this type of use-case 

mc:SetPrimaryPartCFrame(, PositionYouWantToLookAt))

“Creates a CFrame located at pos with it’s lookVector pointing towards the lookAt position.”

  1. fromEulerAnglesXYZ returns a cframe
    you would have to get the difference between the chr position and the hover position, put it into fromEulerAngles, bam, you have your angles now

  2. alternatively,, Vector3) will allow you to get a cframe positioned at vector3 facing the Vector3, just call toEulerAnglesXYZ from that and turn that into angle, but this depends on what mc is, it is another part? its only going to rotate relative to where the head is compared to the mouse hit

1 Like

I have tried this. It gives me:

[Invalid number of arguments: 4]

“mc” is a copied model.

local mf = game.ReplicatedStorage.BuildLights:FindFirstChild(item.Value)
local mc = mf:Clone()

There was a slight bug that didn’t convert the coordinates into a Vector 3 in @Lua_Basics’s code, this fixed version should work for you:

local LookAt =, 0, 0)
mc:SetPrimaryPartCFrame(, hover.y, hover.z), LookAt))

And you’d set the LookAt to any position you want it to look at, for example:

local LookAt = Target.CFrame.Position.

1 Like

Ahh yes, I forgot the Vector3 was more of a fast post for me.

1 Like