Move to mouse click

I have been trying to find a solution to this, but I haven't been able to find anything for it. I am trying to get my main player to move to where the mouse is clicking, but nothing seems to work. This is some code I found somewhere, but I get a NullPointer, also below:

NullReferenceException UnityEngine.Camera.ScreenPointToRay (Vector3 position) (at C:/BuildAgent/work/6bc5f79e0a4296d6/Runtime/ExportGenerated/Editor/Graphics.cs:674) Paddle.Update () (at Assets/Game 4 - 3D breakout/Scripts/Paddle.cs:20)

if (Input.GetKeyDown(KeyCode.Mouse0)) {
        if (Input.GetMouseButtonDown(0)) {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit, 1000.0f)) {
                Vector3 newpos = new Vector3(hit.point.x, 0.5f, hit.point.z);
                transform.position = newpos;
            }
        }
    }

Any ideas would be appreciated, thanks in advance.

got loads of answers for you right here