Object reference not set to an instance of an object UNITY 2d Add Force

Hello i am having problems moving an object using add force in unity2d

The Error im getting is:
NullReferenceException: Object reference not set to an instance of an object
Walk.Update () (at Assets/CharacterScripts/Movement/Walk.cs:18)

And this is my code so far:

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

public class Walk : MonoBehaviour
{
   
    public Rigidbody2D rb2D;
    public float force = 5;
    private void Start() {
        rb2D = gameObject.AddComponent<Rigidbody2D>();
    }
    void Update()
    {
       
        if (Input.GetKeyDown("d"))
        {
            rb2D.AddForce(new Vector2(0f, force), ForceMode2D.Impulse);
        }
       


    }
}

No idea why you’re manually adding a component there, why not add it in the Editor?

Anyway, you should not make the “rb2D” field public, make it private. If it’s public, the component will serialize it. You don’t want that.