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.
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.
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)