remove duplicate gameobject after use dontdestroyonload

how to remove duplicate player switch scene,
this is my code player

private static bool playerExits;
    private void Awake()
    {
        if (!playerExits)
        {
            playerExits = true;
            DontDestroyOnLoad(gameObject.transform);
        }
        else
        {
            Destroy(this);
        }
    }

Hello there.

You are declaring the variable playerExits as static. So, all instances of this script will “share” the same value, But, with his code is imposible to distinguish which player is the “real” and which is the new copy that must be destroyed.

You should learn about singletons (are made exactly for this propuses), but if dont want, just make something like this, so the real player instance will have a variable telling that is the real.

private static bool playerExits;
private bool thisPlayerIsTheReal;

  private void Awake()
     {
         if (!playerExits)
         {
             playerExits = true;
             thisPlayerIsTheReal = true;
             DontDestroyOnLoad(gameObject.transform);
         }
         else if (playerExits && !thisPlayerIsTheReal)
         {          
             Destroy(this);
         }
     }

You see the option (playerExits && thisPlayerIsTheReal) does not need to be writen, because that is exactly the object you want to preserve!

Dont just copy and paste, read it, and think what is doing to understand it.

Good luck!