accesing scripts throu raycasthit

RaycastHit hit;

		if(Physics.Raycast(transform.position,transform.forward,out hit,targetDistance)){
			
						
		}

as you can see its very basic what im tring to do is get into the scripts I have tried going throu with transform.parent with no avail and few others stepped away for a bit came back and still no ideas any help would be great.

Assuming you had a possible script named “TheScript” attached to another game object, you could do:

RaycastHit hit;
 
if(Physics.Raycast(transform.position,transform.forward,out hit,targetDistance)){
    TheScript ts = hit.collider.gameObject.GetComponent< TheScript >();
    if (ts != null)
       ts.ExetueSomething();

}