RayCast not working

when I try raycasting it always comes back as did not hit even when it hit something. I used the scipt form unity’s scripting API page; can someone tell me what I might be doing wrong?public class NewBehaviourScript : MonoBehaviour
{

public LayerMask dontHit;

void FixedUpdate()
{
    RaycastHit hit;
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    // Does the ray intersect any objects excluding the player layer
    if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, dontHit))
    {
        Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
        Debug.Log("Did Hit");

    }
    else
    {
        Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 1000, Color.white);
        Debug.Log("Did not Hit");
    }
}

}

You need to change layer of object you are trying to hit to: dontHit.