How would I make the direction of a raycast a GUI frame?

I’ve recently made an OTS gun system. Looks good so far, now I’m into making the raycast stuff though I’m not really experienced with anything raycast-wise.
Here’s my current setup.
Current Setup
What I basically want to do is to have my racast origin the gun, and my Raycast direction the GUI frame. Any way I could do that? Thanks.

You could try using the function which is called “WorldToScreenPoint”

There’s a few steps here.

  1. ScreenPointToRay your gui
  2. Extend the ray
  3. Cast it to figure out what part the gui is hovering over
  4. Cast a different ray from the gun position to the gui hover position to do the shot