Jumping height is inconsistent

Hi, I am making a 3D platformer and I just finished writing the code for movement and jumping. Although the movement works without any issues, the jump mechanism do not work. I tried to change everything but nothing changed. I would be glad for any help thanks.

This is my code:

private void FixedUpdate()
 {
    //WSAD movement
     Move();
 
  //Jump
     if (Input.GetKey(KeyCode.Space) && grounded)
         Jump();

 }
private void Jump()
{
    
    rb.AddForce(transform.up * jumpSpeed, ForceMode.Impulse);
    rb.velocity = new Vector3(rb.velocity.x, 0f, rb.velocity.z);
}

Also when I am not moving, I jump higher. But when I am moving, I jump less.

First thing you are checking Inputs in the FixedUpdate method.

To correct it you need to move the Input Check in the Update method. I have also added a few variables to make sure the jump is hit only once:

private readonly float jumpCooldown = .1f; //you can't change this at runtime (readonly)
private float lastJumpTime;

private bool jumpInput;

private void Update() //Called every frame (60 FPS = 0.1666 seconds)
{ 
     //GetKey needs to be placed in the Update method or you may lose the Input
     jumpInput = Input.GetKey(KeyCode.Space);
}
private void FixedUpdate() //Called every 0.02 seconds (50FPS)
 {
    //WSAD movement
     Move();

     if (jumpInput && grounded)
         Jump();
 }

Second thing you are resetting the Rigidbody.speed to remove the old Jump Force but you can avoid doing this thanks to the cooldown:

private void Jump()
{
    //This check will make sure you can't "fly", better consistency overall
    if (lastJumpTime + jumpCooldown < Time.time) {
        lastJumpTime = Time.time;
        //Better to use Vector3.up
        rb.AddForce(Vector3.up * jumpSpeed, ForceMode.Impulse);
    }
}

Thanks for reply.
I changed the GetKey for GetKeyDown and it fixed my problem. Awesome
But why when I use GetKey the player jumps inconsistently ? Also how I can make a player jump when holding the space without pressing the space each time.

Why I wrote this code rb.AddForce(transform.up * jumpSpeed, ForceMode.Impulse); I followed a tutorial on YouTube (which turn out to not work) and the guy said that you must write this line of code to prevent the player to jump at different heights.
EDIT: Just realized that I wrote that line of code after AddForce but the guy have that line of code before AddForce.

  private void Move()
  {
      moveDirection = transform.forward * moveY + transform.right * moveX;

      if (grounded)
          rb.AddForce(moveDirection.normalized * playerSpeed * 10f, ForceMode.Force);
  }

The bool grounded works like this. If player OnCollisionEnter with ground then grounded is true. When player OnCollisionExit with ground then grounded is false.