Unable to have a projectile face the mouse in a tool

script.Parent.SendMouse.OnServerEvent:Connect(function(plr,mousepos)

local copy = game.ServerStorage.Projectiles.MelterShot:Clone()

copy.Parent = game.Workspace

copy.Go.Disabled = false

copy:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.FirePoint.Position,Vector3.new(mousepos)))

end)

Im trying to have a projectile face the mouse as its fired from a gun. the projectile does spawn at the part:“FirePoint” and it does go forward it just wont rotate to face the mouse.
“mousepos” is “Mouse.Hit”

1 Like

Instead of:

copy:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.FirePoint.Position,Vector3.new(mousepos)))

Replace it with:

copy:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.FirePoint.Position,mousepos.Position))

The issue was that Vector3.new(mousepos) doesn’t return the position of the CFrame. It will always return the Vector 0, 0, 0 if you tried doing this for any CFrame.

The correct way is: mousepos.Position.

2 Likes

Your script looks (nearly) perfect, so it probably depends on the anatomy of the projectile. What movers are you using to move it forward?

I have run into a new problem, when I fire the projectile towards a cancollide false part the mouse causes the projectile to bounce off course. is there a way for me to have the mouse ignore cancollide false parts?

You could use Mouse.TargetFilter.
If you have multiple parts that you want to ignore, you would have to make a separate folder/model for the parts.

Example:

image

Code:

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