Slider.value returns NullReferenceException: Object reference not set to an instance of an object

The code is very simple, and its returning the value from the debug to console so its working but returning an error I have no idea why.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class PlayerLogic : MonoBehaviour
{
    public Slider PlayerHealth;
    public int Health = 100;

    public void Start()
    {
        PlayerHealth = transform.GetChild(0).GetComponent<Slider>();
        Debug.Log(PlayerHealth.value);
    }

What you are trying to do here is get a Slider component from the very first child of the current GameObject.

Then without even verifying that you have a valid reference to the Slider you try to use it whereupon you get an error because PlayerHealth is null.

First, you have PlayerHealth set as a public variable so if you set it in the inspector then as soon as you do this

PlayerHealth = transform.GetChild(0).GetComponent<Slider>();

you have lost the value that you previously set.

Also, where is the Slider component located? Because if it is null then it is not located on the very first GameObject under the current GameObject.

If you inst on using GetComponent() and not the inspector the you may want to first do a Find(), for example

if (PlayerHealth == null)
{
    GameObject go = GameObject.Find("Player Health"); // looks for a GameObject with the name "Player Health" - you may need to change this
    if (go != null)
    {
        PlayerHealth = go.GetComponent<Slider>();
    }
}

if (PlayerHealth != null)
{
    Debug.Log(PlayerHealth.value);    
}