OnCollisionEnter2D not working properly

Ive looked through almost every thread with no nothing working. Here’s my code:

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

public class MoveLeftRight : MonoBehaviour
{
    public float speed = 5.0f;
    public float leftLimit = -5.0f;
    public float rightLimit = 5.0f;
    public float jumpForce = 10.0f;
    public LayerMask groundLayer;
    private Rigidbody2D rb;
    private bool isGrounded;

    void Start()
    {
      
        rb = GetComponent<Rigidbody2D>();
    }

    void OnCollisionEnter2D(Collision2D collision)
    {
     
        if (collision.gameObject.layer == LayerMask.NameToLayer("Ground"))
        {
            isGrounded = true;
        }
    }

    void OnCollisionExit2D(Collision2D collision)
    {
      
        if (collision.gameObject.layer == LayerMask.NameToLayer("Ground"))
        {
          
            isGrounded = false;
        }
    }

    void Update()
    {
     
        isGrounded = Physics2D.OverlapCircle(transform.position, 0.1f, groundLayer);

      
        transform.position += Vector3.right * Input.GetAxis("Horizontal") * speed * Time.deltaTime;

      
        transform.position = new Vector3(Mathf.Clamp(transform.position.x, leftLimit, rightLimit), transform.position.y, transform.position.z);

       grounded
        if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
        {
            rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
        }
    }
}

Everything in the code works as normal. When I set the layer of the object using the script it jumps, only reason im not doing that is because it would infinitely be jumping. The two objects are colliding when I check the contacts in the inspector.
Player inspector

Ground inspector

With Physics (or Physics2D), never manipulate the Transform directly. If you manipulate the Transform directly, you are bypassing the physics system and you can reasonably expect glitching and missed collisions and other physics mayhem.

Always use the .MovePosition() and .MoveRotation() methods on the Rigidbody (or Rigidbody2D) instance in order to move or rotate things. Doing this keeps the physics system informed about what is going on.

https://discussions.unity.com/t/866410/5

https://discussions.unity.com/t/878046/8

OnCollisionEnter2D works perfectly fine. Your script isn’t however.

There are far easier methods to detect grounded-state or just “is touching” state. Here’s a video which links to my PhysicsExamples GitHub repo so you can see it: