I'm really new to coding and I've made a stickman using rigidbody2d but I want to set a max velocity for it

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

public class Movement : MonoBehaviour
{

public GameObject leftLeg;
public GameObject rightLeg;
Rigidbody2D leftLegRB;
Rigidbody2D rightLegRB;
public  Rigidbody2D rb;

public Animator anim;
[SerializeField] float maxspeed = 10f;
[SerializeField] float speed = 2f;
[SerializeField] float jumpHeight = 2f;
[SerializeField] float legWait = .5f;

private bool isOnGround;
public float positionRadius;
public LayerMask ground;
public Transform playerPos;


// Start is called before the first frame update
void Start()
{
    leftLegRB = leftLeg.GetComponent<Rigidbody2D>();
    rightLegRB = rightLeg.GetComponent<Rigidbody2D>();
    anim = GetComponent<Animator>();

}

// Update is called once per frame
void Update()
{
    

    if (Input.GetAxisRaw("Horizontal") != 0)
    {
        if (Input.GetAxis("Horizontal") > 0)
        {
            anim.Play("WalkLeft");
            StartCoroutine(MoveRight(legWait));
        }
        else
        {
            anim.Play("WalkRight");
            StartCoroutine(MoveLeft(legWait));

        }

    }
    else
    {
        anim.Play("idle");
    }
    isOnGround = Physics2D.OverlapCircle(playerPos.position, positionRadius, ground);
    

    if (isOnGround == true && Input.GetKeyDown(KeyCode.Space))
    {

        leftLegRB.AddForce(Vector2.up * (jumpHeight * 1000));
        rightLegRB.AddForce(Vector2.up * (jumpHeight * 1000));
    }

}

IEnumerator MoveRight(float seconds)
{

    leftLegRB.AddForce(Vector2.right * (speed * 1000) * Time.deltaTime);
    yield return new WaitForSeconds(seconds);
    rightLegRB.AddForce(Vector2.right * (speed * 1000) * Time.deltaTime);

    if (rightLegRB.velocity.x > maxspeed)
        rightLegRB.AddForce(Vector2.right * (speed / 10) * Time.deltaTime , ForceMode2D.Impulse);
}

IEnumerator MoveLeft(float seconds)
{
    rightLegRB.AddForce(Vector2.left * (speed * 1000) * Time.deltaTime);
    yield return new WaitForSeconds(seconds);
    leftLegRB.AddForce(Vector2.left * (speed * 1000) * Time.deltaTime);

    if (leftLegRB.velocity.x > maxspeed)
        leftLegRB.AddForce(Vector2.left * (speed / 10) * Time.deltaTime , ForceMode2D.Impulse);
}

}

When you use AddForce, you are getting Physics to calculate velocity for you. So, if you want to limit velocity, you have to limit rigidbody2D.velocity. The speed is given by rigidbody2D.velocity.magnitude and you want to limit that. You can limit the magnitude using the ClampMagnitude method. So, create a variable with the max speed and add this to your code:

private void FixedUpdate()
{
    rb.velocity = Vector2.ClampMagnitude(rb.velocity, maxSpeed);
}

Just take care, though. If you are using relying on Physics to calculate gravity for you, you don’t want to override any calculations that the Physics system has made so make sure this works in your case.

I see that you are using AddForce in quite a few places. The guidelines over how to use AddForce are not obvious and you should read a bit more about this. This post by @Bunny83 may help. In short, you should be applying AddForce in FixedUpdate and not applying Time.DeltaTime. Typically, you will collect input in Update, store it in a variable and read that variable in FixedUpdate to instruct the AddForce on what to do.