Send message when player disconnect, error when 2 disconnect in same time

Hello everyone, i have not find the answer of this problem, i have code like this:

void Start() {
    if (isServer) {
        gameObject.GetComponent<NetworkIdentity>().connectionToClient.RegisterHandler(MsgType.Disconnect, OnDisconnectClient);
        gameObject.GetComponent<NetworkIdentity>().connectionToClient.RegisterHandler(MsgType.Connect, OnConnectClient);
    }
}

void OnConnectClient(NetworkMessage netMsg) {
    p_list.add(login);
}

void OnDisconnectClient(NetworkMessage netMsg) {
    if (login.Length > 1) {
       p_list.remove(login);
       Rpc_addTchat("\n" + login + " has quit !");
   }
  Destroy(gameObject,0.1f);
}

And, i have make many test but when a player disconnects it sends as many times the disconnection of the first player who has disconnected that there were players who are disconnected at the same time.

When i have player A and player B, if player B and fast after player A disconnect, i have 2 message for the player B.

And player A is not remove (if i delete this code is remove), and is say “the class is destroy” after the first time, but i have already test with out destroy and i say 2 disconnect for 1 same player and the second player, is never say disconnect.

Is that what I misunderstood? :frowning:

I’m having trouble understanding this code or what it’s trying to do:

  1. What is login? Where is login coming from? What sets that? You really should be getting client info from the network message.

  2. Why are you calling Destroy(gameObject) in OnDisconnectClient? This makes it so if any client disconnects, the server’s gameObject is destroyed. I’m pretty sure you don’t want this.