[HELP!] Run in opposite direction on wall collision

Hi! Im working on an 2d platformer. I want the player to run in the opposite direction once it hits a wall collider. I can’t get it working.

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

public class playerController : MonoBehaviour
{

    public Rigidbody2D rb;

    public float movementSpeed = 5f;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void FixedUpdate()
    {
        transform.position += transform.right * movementSpeed * Time.deltaTime;
    }

    void OnCollisionEnter2D(Collision2D other)
    {
        if (other.gameObject.tag == "wallright")
        {
            Vector2 theScale = transform.localScale;
            theScale.x *= -1;
            transform.localScale = theScale;
        }

        if (other.gameObject.tag == "wallleft")
        {
            Vector2 theScale = transform.localScale;
            theScale.x *= 1;
            transform.localScale = theScale;
        }
    }
}

@ItsMelvin Instead of changing the scale of your character, maybe you can multiply you speed with the opposite value of your current MovementSpeed like this:

if (other.gameObject.tag == "wallright")
{
              transform.position += transform.right * -movementSpeed * Time.deltaTime;
}

So you need to record which direction the player is going in, then reverse that.

under movespeed:

public float playerdirection = 1; // for right

then in movement:

transform.position += transform.right * playerdirection * movementSpeed * Time.deltaTime;

then in the colliders:

 if (other.gameObject.tag == "wallright")
 {
     playerdirection = -1;
 }

 if (other.gameObject.tag == "wallleft")
 {
     playerdirection = 1;
 }