LookVector cannot be assigned to

I’m trying to make a part face towards where my HumanoidRootPart is facing but it gives me the error “LookVector cannot be assigned to” here is the script

local m6d = Instance.new("Motor6D", script.Parent)
m6d.Part1 = script.Parent
game.Players.PlayerAdded:Connect(function(d)
	d.CharacterAdded:Connect(function(c)
		m6d.Part0 = c.HumanoidRootPart
		script.Parent.CFrame.LookVector = c.HumanoidRootPart.CFrame.LookVector
	end)
end)```

All CFrame properties cannot be assigned to, you’ll need to set their CFrame to a newly constructed one.
The overload,

CFrame.new(Position : Vector3, LookAt : Vector3)

could be used here, likewise:

CFrame.fromMatrix(Position : Vector3, RightVector : Vector3, UpVector : Vector3, LookVector? : Vector3)

An example of using fromMatrix would look like:

local Forward = (script.Parent.Position - c.CFrame.LookVector).Unit
local UnitUp = Vector3.fromAxis(Enum.Axis.Y)
local Right = Forward:Cross(Up)
local Up = Right:Cross(Forward)
script.Parent.CFrame = CFrame.fromMatrix(script.Parent.Position, Right, Up)

You have to use a constructor.

local pos = script.Parent.CFrame.Position
script.Parent.CFrame = CFrame.new(pos, pos + c.HumanoidRootPart.CFrame.LookVector)
3 Likes

it won’t face towards where my HumanoidRootPart is facing its still facing away from it.

script.Parent.CFrame = CFrame.new(pos, c.HumanoidRootPart.Position)

if you want it to look at the HRP

3 Likes