Hard to explain in title, but raycast help

I am trying to create a sort of “stun” feature for my game. When my flashlight shines on an entity, it i want it to stun them, but I am stuck as to how I would check if the light is shining on the player. I have already tried raycasting, but it was very inconsistent. I might have implemented it incorrectly, but I would just like some assistance figuring out the way I could check. Thanks for any help you can provide.

Do you want the stun to happen if the player points directly at the entity, or if the entity is in a cone shaped beam?

Hey I know this is an old post but I’m curios if you ended up finding a solution? Currently trying to implement something similar. Found this post while searching for answers lol