Look vector not working?

You you should be referencing an object, not a vector position

no, but if I directly reference the object, then it will clone on top of the players head

I did 30chars…

1 Like

That might be due to physics, if the object isn’t anchored and is collidable then it’ll push the two objects apart. Either anchor the clone or make it uncollidable.

But, I want it so that it clones in front of the character

What you want to do is the get the CFrame Position of the Head, not the vector position

I am getting the CFrame with .CFrame though, but it still has a vector issue. And I’m not referencing .Position or anything:

game.Players.LocalPlayer.Character:WaitForChild("Head")

Try this:
Cloned:SetPrimaryPartCFrame(TheHeadOfThePlayersCharacter.CFrame * CFrame.new(0, 0, 4))

You didn’t add the position, it’d just spawn at the LookVector which is a unit vector. (0-1)
The way I put it above will set it to the head’s position and rotation + offset of 4 on Z-Axis (Z being depth, so forward due to the rotation being included, if that doesn’t work try setting it to 4, 0, 0 or the negative variations of them.)

Although you might want to use the HumanoidRootPart instead to position the clone. (Unless it’s a specific case I guess.)

2 Likes

@Dysche’s Solution should work and This might Help in the future(or whenever):

(Sorry for all the dumb replies i made, im tired lol)

1 Like

It doesn’t work, I tried using the humanoidrootpart but it brings up the same error as before:L
08:18:02.195 - CFrame is not a valid member of Vector3

@Jaycbee05 @DragRacer31 @Dysche
For more info that I think I didn’t need at that time:
The part i am cloning is a model from the replicated storage, and I’m setting the parent to workspace. All this is done on a server script when a remote event is fired. In the local script I put in all the things like finding the character and what to clone.

What type is the object you’re trying to reference? It says you’re trying to call .CFrame on a Vector3, can you post more code maybe?

I’m referencing the players head/humanoid root part from a local script, then using a remote event to transfer that information to a server script.

Using the player who fired parameter, try doing:

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

“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