Grabbing MonoBehavior object from collision

I have a function that does a Raycast and when it hits the correct object, it should do something specific with that object. The problem is that I cannot figure out how to get the object that extends from MonoBehavior.

Here is the code I’ve been using:

void checkForHit(Vector3 position) {
	var ray = Camera.main.ScreenPointToRay(position);
	RaycastHit rayHit;
	
	if(Physics.Raycast(ray, out rayHit)) {
		if(rayHit.collider.tag == "specificTagToThisObj") {
			var monoObj = rayHit.transform.gameObject as MyMonoBehaviour; //This line has an error.
		}
	}
}

Is this possible to do?

MonoBehaviour basically means a script. In code, scripts are usually referred to as Components. So, I suspect you actually want to access a component that is on the hit object. So, you probably want:

Wibble w = rayHit.transform.gameObject.GetComponent<Wibble>();

where Wibble is the name of your script/class.