how to find the child of an object i hit with raycast

Like the title says i need to find the children of an object i hit with a raycast so far i have

float tempDist = 0f;
							float prevDist = 0f;
							foreach (Transform child in transform)
							{
								if(tempDist != null)
								{
									prevDist = tempDist;
								}
								tempDist = Vector3.Distance(hit.point, child.transform.position);
								if(tempDist > prevDist)
								{
									furthestAway = child.collider.name;
								}
								if(child.collider.name == "posXLock")
								{
									posX = child.transform.position;
								}
								else if(child.collider.name == "negXLock")
								{
									negX = child.transform.position;
								}
								else if(child.collider.name == "posZLock")
								{
									posZ = child.transform.position;
								}
								else if(child.collider.name == "negZLock")
								{
									negZ = child.transform.position;
								}
							}

but that returns the object the script is on how do i make it do the one i hit with a raycast

You did not include your Raycast() code here. Assuming that ‘hit’ is the RaycastHit returned by the Raycast(), just do:

 foreach (Transform child in hit.transform)