How to get rid of NullReferenceException when using Raycast?

In my topdown 3d project i am using raycast to detect enemy and then attack the enemy. My ray is looking for Enemy script component and because of that i am getting null reference error every second before i start looking at enemy. How do i get rid of that ?

Would you mind to share some of the code so we can help you?