Can't understand error message

I’m making a 2d platformer game using c# and I’ve got this error message that I don’t understand how to fix it. There aren’t any red squiggly lines under the code.
Here’s the error message:
NullReferenceException: Object reference not set to an instance of an object
Bounce_pad.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Sripts/Bounce_pad.cs:14)

Here’s the code I’m currently using:

private Rigidbody2D rigidbody2d;
void OnTriggerEnter2D(Collider2D other)
{

    if (other.tag == "Player")
    {
        float BounceHeight = 10f;
        rigidbody2d.velocity = Vector2.up * BounceHeight;
    }

}

Did you initialize the rigidbody2d?
You need to pass a reference of the rigidbody2d through the inspector / initialize it in script using GetComponent

Assuming that line 14 in your code is the one starting rigidbody2d.velocity = ..., this means that the rigidbody2d variable has not been set.

It should be a safe assumption, because that’s the only line in what you’ve shown us that could cause that exception.

Note that it’s an “exception”, thrown at runtime, not a compiler error, which is why it doesn’t show as an error in your code.

You either need to make that field public and assign it in the inspector, or find some other way of finding where the rigidbody is and assigning the field.

An example of the latter approach would be that If the rigidobdy2D component is on the same gameobject as the above script, you could add an Awake() function to get hold of it like this…

Awake()
{
    rigidbody2D = GetComponent<Rigidbody2D>();
}