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)
wait()
mc:SetPrimaryPartCFrame(CFrame.new(hover.x, 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 = Vector3.new(hover.x, 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(CFrame.new(Firstpos, PositionYouWantToLookAt))
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
alternatively, Cframe.new(Vector3, 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