[C#] can't reference to an object that is being instantiated

For some reason I can’t get a reference to an object that I’m instantiating:

    public Transform LocationPrefab;
    public static GameObject[,] ArrayOfLocations = new GameObject[48, 15];
    public LocationScript LocScr;
    public static float Radius = 4;

    public void BuildPlanet()
    {
        for (int counterx = 0; counterx < ArrayOfLocations.GetLength(0); counterx++)
        {
            for (int countery = 0; countery < ArrayOfLocations.GetLength(1); countery++)
            {
                Vector3 locationPosition = new Vector3(counterx, countery, 0);
                LocScr = Instantiate(LocationPrefab, Vector3.zero, Quaternion.identity) as LocationScript;
                print(LocScr);
                LocScr.inclination = 90 - (15 * (countery + 5) / 2);
                LocScr.azimuth = 7.5f * counterx;
                LocScr.transform.Translate(Radius, 0, 0);
                LocScr.transform.RotateAround(Vector3.zero, Vector3.forward, LocScr.inclination);
                LocScr.transform.RotateAround(Vector3.zero, Vector3.up, LocScr.azimuth);
                ArrayOfLocations[counterx, countery] = LocScr.gameObject;
            }
        }
    }

Result:
Prints “null” and than “NullReferenceException: Object reference not set to an instance of an object”.

I have no idea why won’t it reference it, even the example in scripting reference looks similar. var = instantiate () as class; and one can than use this var when it’s needed later on. What am I missing?

do you have dragged the prefab which shall be instantiated onto the LocationPrefab (not LocScr!) variable in the inspector?

Instantiate returns a GameObject but you’re trying to assign it to a LocationScript.

Yes, I have dragged it.
I’ve changed it right now to GameObject, as I did few times before with no different result.

However, it actually was a little bit of both your answers ;D .
After changing it to GameObject I’ve deleted the reference that was linked in Unity Editor and redragged it again and it is working just fine.