C# Raycast isn't working?

For some reason my raycast isn’t working. I was wondering if someone could help me. Here is my code:

void Update () {
        if (Input.GetMouseButtonDown(0))
        {
            
            RaycastHit hit;
            Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Ray ray = Camera.main.ScreenPointToRay(mousePos);
            if (Physics.Raycast(ray, out hit, Mathf.Infinity, 0)) {
                Debug.Log("Works");
                
            }
        }
}

For some reason it isn’t logging the message.

You are converting the mouse screen point to world coordinates, then passing the world coordinates into ScreenPointToRay which requires a screen point. So that won’t work. Just pass in Input.mousePosition instead.