Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why will this lookVector not work? It will not make it face the same way character is facing.

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

mouse.KeyDown:connect(function(key)
	if key == "f" then
		local part = Instance.new("Part")
		local fire = Instance.new("Fire",part)
		local Mesh = Instance.new("SpecialMesh",part)
		Mesh.MeshId = "rbxassetid://475201433"
		Mesh.Scale = Vector3.new(0.1,0.1,0.1)
--		Mesh.TextureID = "rbxassetid://475201512"
		part.Parent = workspace
		part.Name = 'FireBall'
		part.CanCollide = false
		part.Anchored = true
		part.Position = plr.Character.Torso.Position
		part.CFrame.lookVector = CFrame.new(plr.Character.Head.CFrame.lookVector) -- Problem here
	end
end)

Error: 20:58:21.502 - lookVector cannot be assigned to

It makes the part but it will not face the way the player is facing.

1 answer

As the error you shared indicates, you cannot directly set the lookVector of a Part. You can, however, set the Position and the CFrame properties.

You can set the CFrame rotation of the Part to the direction of the player's head like this:

head_cframe = plr.Character.Head

-- remove the positional component from the CFrame, left with rotation only
head_cframe_rotation = head_cframe - head_cframe.p

-- Add the rotational and positional components together 
part.CFrame = head_cframe_rotation + part.Position

This discussion is preserved as it was. New answers, comments, and votes are closed.