local 2 player jumping problem

i have a script on 2 players but when they touch eachother aswell as touch the ground and then stop touching each other but continue to touch the ground they cant jump. can someone help me

this is the script:

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

public class Tom_Movement : MonoBehaviour
{
    public float moveSpeed = 5f;
    public float jumpForce = 5f;

    public GameObject Tim;

    bool isGrounded;

    private void Update()
    {

        if (Input.GetKey(KeyCode.RightArrow))
        {
            gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(moveSpeed, 0f));
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(-moveSpeed, 0f));
        }

        if (isGrounded)
        {
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
            gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, jumpForce), ForceMode2D.Impulse);
            }
        }
    }

    private void OnCollisionEnter2D(Collision2D other)
    {
        if (other.collider.tag == "Ground" || other.collider.tag == "Player")
        {
            isGrounded = true;
        }else if (other.collider.tag == "Ground" && other.collider.tag != "Player")
        {
            isGrounded = true;
        }else if (other.collider.tag != "Ground" && other.collider.tag == "Player")
        {
            isGrounded = true;
        }else if (other.collider.tag == "Ground" && other.collider.tag == "Player")
        {
            isGrounded = true;
        }
    }

    private void OnCollisionExit2D(Collision2D other)
    {
        isGrounded = false;
    }
}

maybe your isgrounded is set to false when the 2 players stop touching eachother

try adding in this part

   private void OnCollisionExit2D(Collision2D other)
    {
     
if (other.collider.tag == "Ground")
        {
            isGrounded = false;
        }
    }

I’ve tried that already it doesn’t work… i think the problem is if it is touching both the player and the ground then isgrounded becomes true but once you stop touching the other the isgrounded becomes false automatically because it has no if statements. but i’ve tried addding if statements and it doesn’t work… maybe there is something i forgot