Unet Binary Serialization

Hi all, i want to ask a question about unet binary serialization. The problem is that i can’t save data to server’s pc, codes are always trying to do it on client’s pc. Here is the code

    [Command]
    void CmdDisablePlayer()
    {
        playerManagerScript.RemovePlayer(gameObject);
        NetworkManagerEdited.singleton.StopClient();
        NetworkManagerEdited.singleton.StopHost();
    }


///////////////////////////////////////////////////////////////////////////////////////////////////////////

    public void RemovePlayer(GameObject _player)
    {
        PlayerLoadInfos infos = new PlayerLoadInfos();
        infos.playerName = _player.name;
        infos.playerPositionX = _player.transform.position.x;
        infos.playerPositionY = _player.transform.position.y;
        infos.playerPositionZ = _player.transform.position.z;

        players.Remove(_player);


        //Store player properties in database
        StorePlayerData(infos);
    }
    void StorePlayerData(PlayerLoadInfos _infos)
    {
        BinaryFormatter bf = new BinaryFormatter();
        FileStream file = File.Create(Application.persistentDataPath + "/Saves/" + serverNamePrivate + "/Players/" + _infos.playerName + ".dat");

        bf.Serialize(file, _infos);

        file.Close();

    }

first code (cmd) is on player object, second one is on a non-static object.

Are you calling RemovePlayer anywhere else in your code? You could check for isServer in RemovePlayer or StorePlayerData to prevent attempts to run it on the clients.

What error are you getting when you try to save data on the server?

RemovePlayer is on non-player object which name is PlayerManager. I get no error for this. If i run 2 game in same pc then everything works because when you create a host, game creates directories for data, and when you exit and save they both saving data to directories, but if i connect from other pc, this code doesn’t work for client.Most likely, it errors like that the directory path you are trying to reach is not found cause of client doesn’t create directory for the server. So client tries to save data on its pc. It means i actually can’t reach the server from client. How can i do about that ? And thanks for the reply @Joe-Censored

any other suggestions ??