Counteract current speed of player

How would I counteract the speed of the player after I stop pressing movement inputs? I need a solution that uses addforce modifying velocity causes lot’s of problems for my player controller.

Code i’m using to move:.

        float x = Input.GetAxisRaw("Horizontal");
		float z = Input.GetAxisRaw("Vertical");
		rb.AddForce(transform.forward * z * speed, ForceMode.Acceleration);
		rb.AddForce(transform.right * x * speed, ForceMode.Acceleration);


rb.velocity.magnitude will return the speed of the object in units. Reverse the direction of the velocity multiplied by the speed.

rb.AddForce(-br.velocity * rb.velocity.magnitude, ForceMode.Acceleration);