Raycast to mouse position and camera script not cooperating

This is usually something that happens when you use the PlayerMouse object to determine the end point of a cast. You should instead make use of the function Camera.ViewportPointToRay, which will return a unit ray from the camera in the direction of where the mouse is located. You can then use the origin over mouse.Hit.p (by the way, CFrame.p is deprecated in favour of CFrame.Position).

Other than that, small advisory of the way you create the ray visualisation part: don’t use the parent argument on Instance.new.