Invalid argument #1 (CFrame expected, got Vector)

So, I’m implementing a shiftlock for mobile in my game but I came across with this error and I’m confused because I am still learning the CFrames and Vectors.

Code:

--// This is where the error pops up
HumanoidRootPart.CFrame = CFrame.new((HumanoidRootPart.Position) * CFrame.Angles(0, math.atan2(-LookVector.X, -LookVector.Z), 0))

You are trying to apply CFrame to a Vector3 type, consider changing the formula to following:
CFrame.new(HumanoidRootPart.CFrame.Position) * CFrame.Angles(0, math.atan2(-LookVector.X, -LookVector.Z), 0)

CFrame.new() converts Vector3 to CFrame, and then you apply CFrame transform to it.

1 Like

I’ve tried this but the same problem appeared.

1 Like

Please provide the errors that are happening in the console, its harder to debug the cause without errors, because there is no clue why would it error. Also I’m currently mobile so I cannot replicate the environment. I’ll find a solution to this if no further assistance will be provided by others. Using console and breakpoints to debug the cause is the key to solve the errors that happen.

1 Like

Ok so…

This is the snippet code:

And the console error:
image

1 Like

Pay closer attention to the brackets I placed and pay attention to your brackets. They’re important here.

Whats actually happening here is you take the position of humanoid rootpart and apply a CFrame to it, (inside CFrame.new(), the calculation looks like this: (HumanoidRootPart.Position) * CFrame.Angles(0, math.atan2(-LookVector.X, -LookVector.Z), 0), which is not what you expect to happen. You must first take position of rootpart, convert it to CFrame with CFrame.new(HumanoidRootPart.CFrame.Position) and then do CFrame math)

1 Like

Oh yeahhhhhh… I didn’t notice the parenthesis. and It works now!

Thanks for the help.

No problem. Have a great Tuesday.

1 Like