addforce not working on my instantiated objects.

I’m trying to make walls spawn and move towards my player across a plane, but the force doesn’t affect the walls at all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ObstacleSpawner : MonoBehaviour {

    public GameObject[] Obstacles;
    public float wallSpeed;

    private float Timer;
    private int spawnIndex;
    private Rigidbody rb;


	// Use this for initialization
	void Start () 
    {
         
	}
	
	// Update is called once per frame
	void Update () 
    {
        Timer += Time.deltaTime;

        if(Timer >= 2)
        {
            spawnIndex = Random.Range(0, Obstacles.Length);
            Instantiate(Obstacles[spawnIndex]);

            Obstacles[spawnIndex].GetComponent<Rigidbody>();
            rb.AddForce(0, 0, wallSpeed);

            Timer = 0;
        }
	}
}

The rb variable is not referencing a rigidbody.
It should be written like this rb = obstacles[spawnindex].getcomponent(); then you can write rb.addforce. because right now when u use rb the program doesn’t know what rigidbody your talking about