Look vector not working?

“TheHeadOfThePlayersCharacter”

But is it really the Head of the Player’s Character? From what I’m seeing, that variable is a Vector3 value, not an Instance value, and the script seen here tries to index a CFrame of a Vector3, which doesn’t exist.

Also, assuming this did work, it wouldn’t spawn 4 studs in front of your head, but instead spawns 4 studs from the origin, relative to the heads direction.

You can fix this by doing the following:

 ...TheHeadOfThePlayersCharacter.Head.Position + (TheHeadOfThePlayersCharacter.Head.CFrame.lookVector * 4)..

…without the “…”, of course.

1 Like

It doesn’t have any errors now, but it clones and spawns so far away(like 100 studs!) I tried decreasing the multiplication but it did nothing

Going back to @Dysche’s method, you could try just adding to the CFrame:

Cloned:SetPrimaryPartCFrame(player.Character.Head.CFrame * CFrame.new(0,0,4))
1 Like

The Z component there should be negative. Negative Z = forward. Negative X = left. Negative Y = down.

As for the OP, you should use CFrame multiplication instead of LookVector. Your original problem though was that TheHeadOfThePlayersCharacter was a Vector3 value. Maybe you are storing their Head.Position as mentioned above. If you wanted it to work as intended you must find what TheHeadOfThePlayersCharacter is set to and resolve the issue.

As for CFrame multiplication, multiplying a CFrame moves it relative to its look direction.

-- These are all relative to the direction of the player's head. If they are upsidedown cframe3 would appear to move down since that is up relative to them.
local cframe1 = headCFrame * CFrame.new(0, 0, -4) -- Four studs forwards
local cframe2 = headCFrame * CFrame.new(-4, 0, 0) -- Four studs left
local cframe3 = headCFrame * CFrame.new(0, 4, 0) -- Four studs up

If you want to cancel any rotation applied to the item you can do this:

itemCFrame = CFrame.new(itemCFrame.p) -- Cancel out rotation
itemCFrame = CFrame.new(itemCFrame.p, itemCFrame.p + customLookVector) -- With custom LookVector

If you want only the Y rotation to change (so the item will face the direction of the player’s X and Z position but not their vertical position) I can give that as well but its a little more complicated.

2 Likes

How would I rotate it? With ElularAngles?

Probably. That’s what I would use. You could also create a CFrame at the origin facing the player’s X Z components (the Y would be 0) and use the LookVector.

1 Like