Making part face mouse [HELP]

I’ve been trying for a long time to make this part face the direction of the mouse. All the videos I’ve watch it seems to work for them but not so much me.

For some reason when I change the CFrame of the bullet it just completely disappears but without that line I don’t know how to make it face the mouse.

tool = script.Parent
function shoot(player, hit)
	local bullet = Instance.new("Part", workspace)
	bullet.Name = 'bullet'
	bullet.Position = hit.p -- Works fine without line 6
	bullet.CFrame = CFrame.new(bullet.CFrame.Position, hit.p) -- Cancels out line 5
	
end

Because you set the Position first the 6 line will be this:

CFrame.new(hit.p, hit.p) 

This will result in a NAN error you cannot have something look at itself.

I would do this

tool = script.Parent
local handle = tool.Handle

function shoot(player, hit)
	local bullet = Instance.new("Part", workspace)
	bullet.Name = 'bullet'
	bullet.Position = hit.p -- Works fine without line 6
	bullet.CFrame = CFrame.new(handle.Position, hit.p).Rotation + bullet.Position
	
end

This will modify the rotation without effecting the original position line

There’s no need to set the Position, just write:

bullet.CFrame = CFrame.lookAt(--[[Placement]], Hit.Position)
1 Like