NullReferenceException: Object reference not set to an instance of an object PlayerMovement.Update () (at Assets/Script/PlayerMovement.cs:21)

Im Having a hard figuring out what the problem is, so please someone help me i am using the code on visual studio version 2022.2

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

public class PlayerMovement : MonoBehaviour
{
    private CharacterController controller;
    private Vector3 playerVelocity;
    private bool groundedPlayer;
    private float playerSpeed = 2.0f;
    private float jumpHeight = 1.0f;
    private float gravityValue = -9.81f;

    private void Start()
    {
        controller = gameObject.AddComponent<CharacterController>();
    }

    void Update()
    {
        groundedPlayer = controller.isGrounded;
        if (groundedPlayer && playerVelocity.y < 0)
        {
            playerVelocity.y = 0f;
        }

        Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
        controller.Move(move * Time.deltaTime * playerSpeed);

        if (move != Vector3.zero)
        {
            gameObject.transform.forward = move;
        }

        // Changes the height position of the player..
        if (Input.GetButtonDown("Jump") && groundedPlayer)
        {
            playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
        }

        playerVelocity.y += gravityValue * Time.deltaTime;
        controller.Move(playerVelocity * Time.deltaTime);
    }
}

This is the error:

NullReferenceException: Object reference not set to an instance of an object
PlayerMovement.Update () (at Assets/Script/PlayerMovement.cs:21)

Hello! This is a standard answer.

Before coming Unity answers, you must always google what your error means. And learn that in every error message, it says the line of code where is happening.

Null Reference errors occurs when there is some variable with value null when code tries to read it. You need to learn to find your problem by your own. First, check your error code, it says the line where the problem is. Second, You need to debug the code while running, and check the states of the variables of the line at the moment the error occurs,

I’m sure you will detect what variable value is NULL. Then investigate why.

Look for some tutorials on how to debug code while running on your scripting software if don’t know what I’m talking about.

Bye & good Luck!