Error: Invalid number of arguments: 6
Line 7.
As i understand something is wrong with rotation.
It is local script.
My script:
local WorkspaceService = game:GetService("Workspace")
local Camera = WorkspaceService:WaitForChild("Camera")
local Garage = script.Parent:WaitForChild("Garage").Value
local function CFrameChanged()
local InversedOne = Camera.CFrame:Inverse()
local CarCFrame = Garage:WaitForChild("Car"):GetPivot()
local NeedCFrame = CFrame.new(CarCFrame.X,CarCFrame.Y,CarCFrame.Z,math.rad(InversedOne.Rotation.X),0,math.rad(InversedOne.Rotation.Z)) --error here--
Garage:WaitForChild("Car"):PivotTo(NeedCFrame)
end
Camera:GetPropertyChangedSignal("CFrame"):Connect(CFrameChanged)
Thx, no errors, but for some reason it looks like CFrame don’t change at all.
And i tried to print Camera’s CFrame’s Rotation, it always print 0,0,0 for some reason.
The reason the error occurs is because CFrame.new accepts 7 arguments, not 6, the argument that’s missing is qW. However, a cleaner way to do this is the following:
local rot = InversedOne.Rotation
local angles = CFrame.Angles(math.rad(rot.X), 0, math.rad(rot.Z))
local NeedCFrame = CFrame.new(CarCFrame.Position)*angles
CFrame.Rotation returns a copy of itself without the translation/position. You’re trying to get the XYZ of it, but XYZ is the position, not the rotation. So this whole time you’re trying to rotate a CFrame by 0 radians/degrees (because the Rotation CFrame has no position, only rotation).
The solution to this is to get XVector, YVector, and ZVector instead because these show the rotation vector of a CFrame. To actually rotate the CFrame, use CFrame.fromMatrix() as it makes a CFrame using the position and the three rotation vectors.
local WorkspaceService = game:GetService("Workspace")
local Camera = WorkspaceService:WaitForChild("Camera")
local Garage = script.Parent:WaitForChild("Garage").Value
local function CFrameChanged()
local InversedOne = Camera.CFrame:Inverse()
local InversedRotation = InversedOne.Rotation
local CarCFrame = Garage:WaitForChild("Car"):GetPivot()
local NeedCFrame = CFrame.fromMatrix(CarCFrame.Position, InversedRotation.XVector, InversedRotation.YVector, InversedRotation.ZVector)
Garage:WaitForChild("Car"):PivotTo(NeedCFrame)
end
Camera:GetPropertyChangedSignal("CFrame"):Connect(CFrameChanged)
If you don’t understand something or just wanna ask a question, feel free to do so!
Thx, it works, but what if i want to disable XVector and ZVector, it doesn’t work if i disable first one(it rotate only on 180 degrees). I can show video if you want.
This has probably been solved, but setting a CFrame is easy, if done properly.
local position = {0,0,0}
local orientation = {0,0,0}
local cframe = CFrame.new(Vector3.new(position[1],position[2],position[3])) * CFrame.Angles(math.rad(orientation[1]),math.rad(orientation[2]),math.rad(orientation[3]))
--there you go, a new CFrame