lookVector cannot be assigned to
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0 player = game.Players.LocalPlayer hum = player.Character hum.Humanoid.JumpPower = 0 if hum.Torso ~= nil then function onKeyPress(inputObject, gameProcessedEvent) game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0 player = game.Players.LocalPlayer hum = player.Character hum.Humanoid.JumpPower = 0 if inputObject.KeyCode == Enum.KeyCode.W then hum.Torso.CFrame.lookVector = Vector3.new(-0, -0, -1) hum.Torso.CFrame = hum.Torso.CFrame + Vector3.new(0,0,-5) elseif inputObject.KeyCode == Enum.KeyCode.S then hum.Torso.CFrame = hum.Torso.CFrame + Vector3.new(0,0,5) elseif inputObject.KeyCode == Enum.KeyCode.A then hum.Torso.CFrame = hum.Torso.CFrame + Vector3.new(-5,0,0) elseif inputObject.KeyCode == Enum.KeyCode.D then hum.Torso.CFrame.lookVector = Vector3.new() hum.Torso.CFrame = hum.Torso.CFrame + Vector3.new(5,0,0) end end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
i have this grid script that move the player in a grid of 5 studs. i want it to change the lookvector too, but apparantly,
lookVector cannot be assigned to
i get the above error whenever i run this, how do i get it to work right?
.lookVector
is a read-only property of CFrame
s, which means that you cannot edit it yourself directly. However, there are indirect ways of "setting" the lookVector
of a CFrame
. For example:
yourCFrame = CFrame.new( yourCFrame.p, yourCFrame.p + yourLookVector)
will change yourCFrame
so that it has the given yourLookVector
. Line 12 in your script would be:
hum.Torso.CFrame = CFrame.new( hum.Torso.Position, hum.Torso.Position + Vector3.new(-0, -0, -1) )
Mind you that some information is lost by setting the CFrame's
lookVector
this way - namely, the rotation on its z-axis. but it doesn't seem like it would matter in your case. You may want to look at CFrame.fromAxisAngles
instead if you want to preserve the CFrame's
rotation on its z-axis.