Invalid argument #1 (CFrame expected, got Vector3)

Hey everyone! I’ve been trying to use the following thread to make the legs of an R15 character to follow the direction that the character is moving in, but I keep getting a following error on the 8th (edit) line of the script, “invalid argument #1 (CFrame expected, got Vector3).” Would really appreciate a solution and an explanation, because I’m not the best with CFrames.

local RunService = game:GetService("RunService")
local leftLeg = script.Parent.LeftUpperLeg.LeftHip
local rightLeg = script.Parent.RightUpperLeg.RightHip
local centerOfLegs = Vector3.new(0,-.2,0)

local rootCFrame = script.Parent.HumanoidRootPart.CFrame
local moveDirection = game.Players.LocalPlayer.Character.HumanoidRootPart.Velocity.Unit
local moveDirectionRight = CFrame.new(0, 0, 0) * moveDirection * CFrame.fromEulerAnglesXYZ(0, math.rad(90), 0)
local angleLeft = math.atan2(moveDirection.z, moveDirection.x)
local angleRight = math.atan2(moveDirectionRight.z, moveDirectionRight.x)
local rotationCFrame = CFrame.new(rootCFrame.Position, rootCFrame.Position + moveDirection)

RunService.RenderStepped:Connect(function()
	
	leftLeg.C0 = CFrame.new(centerOfLegs) * CFrame.fromEulerAnglesXYZ(0, angleLeft, 0)
	rightLeg.C0 = CFrame.new(centerOfLegs) * CFrame.fromEulerAnglesXYZ(0, angleRight, 0)

end)
2 Likes

Which line does said error occur?

1 Like

Sorry my bad, I removed a couple lines. The line is:

local moveDirectionRight = CFrame.new(0, 0, 0) * moveDirection * CFrame.fromEulerAnglesXYZ(0, math.rad(90), 0)
1 Like

The moveDirection variable should be CFrame, not a Vector3.
You can do this:

local moveDirectionRight = CFrame.new(0, 0, 0) * CFrame.new(moveDirection) * CFrame.fromEulerAnglesXYZ(0, math.rad(90), 0)
3 Likes

This was it! Thanks for the fast response :pray:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.