gameobject stops moving correctly when rotating

when my gameobject rotates and moves forward, it moves left and then right in leke a swaying motion instead of moving forward and rotating. here is the code:

 public float rotationspeed;
    public float speed;
    // Start is called before the first frame update
    
    // Update is called once per frame
    void Update()
    {
     
  
            transform.Rotate(0, 0, 50 * rotationspeed * Time.deltaTime);


        transform.Translate(Vector2.right * speed * Time.deltaTime);


    }`

someone on Reddit called Krcko98 told me this as the answer:
Use a parent for your object and move the parent but rotate the child object. You cannot do both at the same time since you are using the direction of the transform and that depends on the object’s orientation in space directly affected by rotation.