Mouse position is not registering

Good morning everyone. I am using this code to shoot a part

Effect.PrimaryPart.BodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	Effect.PrimaryPart.BodyVelocity.Velocity = CFrame.new(plr.Character.RightHand.Position, mouse.p).lookVector * settings.Speed.Value

It is supposed to shoot the part from the player to the mouse position. The problem is this-

When I use this code in a separate project on its own, it works fine
When I use it in my main project, it sometimes work, sometimes it shoots in the direction the player is facing, and sometimes it shoots in a random direction, most often the opposite way the player is facing.

There are no scripts manipulating the camera position or movement in the main project.

Any idea what I am doing wrong?

1 Like

Code seems ok, but check out if the mouse hits anything unusual like VFX particles or parts.

If so then you will need to blacklist it like the post below.

1 Like

This looks like it might be the solution. There are particles in the Effect which might be messing it up.

I looked at your solution. Where would I apply the mouse filter? Noob question, I know, but I am very new to this…

1 Like

In my solution it uses the newer raycasting so the filter is with the RaycastParams.

1 Like

Thank you. I will try to figure it out

1 Like

mouse.p this is likely invalid, you probably meant mouse.Hit.p instead.

Mouse is internally deprecated. You can only do this in a LocalScript, and use Mouse.Hit.Position instead.