Not all codepaths return a value error C#

This is the full error:
Assets/PlayerShooting.cs(116,11): error CS0161: `PlayerShooting.FindClosestHitObject(UnityEngine.Ray, out UnityEngine.Vector3)': not all code paths return a value

To me I dont see any problems. Does someone else know how I can fix this?

sing UnityEngine;
using System.Collections;


public class PlayerShooting : MonoBehaviour {

	float cooldown = 0;
	FXManager fxManager;
	public GameObject pistol;
	WeaponData weaponData;

	// Use this for initialization
	void Start () {


		fxManager = GameObject.FindObjectOfType<FXManager> ();

		if (fxManager == null) {
			Debug.LogError("What did you do with the FXManager! I can't find it!");
				}
	} 
	
	// Update is called once per frame
	void Update () {
		cooldown -= Time.deltaTime;

		if (Input.GetButton ("Fire1")) {
			Fire ();
				}

	}


	void Fire(){

				if (weaponData == null) {
						weaponData = gameObject.GetComponentInChildren<WeaponData> ();
			
						if (weaponData == null) {
								Debug.LogError ("WHAT DID YOU DO WITH THE WEAPON DATA!");
								return;
						}
				}

				if (cooldown > 0) {
						return;
				}
				
		cooldown = weaponData.fireRate;
				Debug.Log ("Firing");



				Ray ray = new Ray (Camera.main.transform.position, Camera.main.transform.forward);
				Transform hitTransform;
				Vector3 hitPoint;
	
				hitTransform = FindClosestHitObject(ray, out hitPoint);


				if (hitTransform != null) {
						Debug.Log ("Hit" + hitTransform.name);
						Health h = hitTransform.GetComponent<Health> ();
				

						while (h == null && hitTransform.parent) {
								hitTransform = hitTransform.parent;
								h = hitTransform.GetComponent<Health> ();
			
						}
						if (h != null) {
								PhotonView pv = h.GetComponent<PhotonView> ();
						
								//h.TakeDamage(damage);

								
			
								if (pv == null) {
										Debug.LogError ("WHERE DID YOU PUT THE PHOTON VIEW CLASS!");
								} else {
										TeamMember tm = hitTransform.GetComponent<TeamMember> ();
										TeamMember myTm = this.GetComponent<TeamMember> ();


										if (tm == null || tm.teamID == 0 || myTm == null || myTm.teamID == 0 || tm.teamID != myTm.teamID) {
												h.GetComponent<PhotonView> ().RPC ("TakeDamage", PhotonTargets.AllBuffered, weaponData.damage);
										}


								}
			

						}
				
				


				if (fxManager != null) {

						DoGunFX (hitPoint);
				}
		} else {
						hitPoint = Camera.main.transform.position + (Camera.main.transform.forward * 100f);
						DoGunFX (hitPoint);
				}
		}
		


void DoGunFX(Vector3 hitPoint){

		fxManager.GetComponent<PhotonView> ().RPC ("PistolBulletFX", PhotonTargets.All, weaponData.transform.position, hitPoint);
	}

Transform FindClosestHitObject(Ray ray, out Vector3 hitPoint){
		
		RaycastHit[] hits = Physics.RaycastAll(ray);
		
		Transform closestHit = null;
		float distance = 0;
		hitPoint = Vector3.zero;
		
		foreach (RaycastHit hit in hits) {
			if (hit.transform != this.transform && (closestHit == null || hit.distance < distance)) {
				closestHit = hit.transform;
				distance = hit.distance;
				hitPoint = hit.point;
				
				
				return closestHit;
			}
		}
		
		
	}



}

Firstly, the error is correct, FindClosestHitObject does not always return a value. For example, if there are no hits returned by RayCastAll? To fix this I moved the return to outside the foreach. The logic also seemed flawed? You are returning the first transform with a distance < 0? And, not checking against all the hits? Maybe I’m missing something.

    Transform FindClosestHitObject(Ray ray, out Vector3 hitPoint)
    {
        RaycastHit[] hits = Physics.RaycastAll(ray);
 
        Transform closestHit = null;
        float distance = float.Max;
        hitPoint = Vector3.zero;
 
        foreach (RaycastHit hit in hits)
        {
            if (hit.transform != this.transform &&
                  hit.distance < distance)
            {
                closestHit = hit.transform;
                distance = hit.distance;
                hitPoint = hit.point;
            }
        }
        return closestHit;
    }

This method can now return null, so you may want to check if the return is null when calling it and before using the returned transform / out vector. I hope that helped =D