Is it possible to call a [Command] from OnDestroy()?

So my players are only destroyed when leaving the game - other times they will just be teleported as ghosts to a respawn spot. When their connection drops or the server is shutting down they are also destroyed. Right now I have the following code:

[Command]
void CmdSave()
{
}
void OnDestroy()
{
    CmdSave();
}

This throws an error within unity:

Command function CmdSave called on server.
UnityEngine.Debug:LogError(Object)
PlayerCharacter:CallCmdSave()
PlayerCharacter:OnDestroy() (at Assets/PlayerCharacter.cs:75)

So can we not call a command from OnDestroy() or something? How should I do it instead?

Have you tried making another method which holds those two?
Like this?

    void drop() {
       CmdSave();
       OnDestroy();
    }

It’s possible that when the destroy function is called the connection is lost.
I hope i’m understanding your issue correctly.

So what I ended up doing was the following:

    [Server]
    void Save()
    {
        
        Debug.Log("Called save on: " + Name);
        if (!System.IO.Directory.Exists(Application.persistentDataPath + "/players/"))     //if directory doesn't exist create it
        {
            System.IO.Directory.CreateDirectory(Application.persistentDataPath + "/players/");
        }
        BinaryFormatter bf = new BinaryFormatter();
        FileStream file = File.Create(Application.persistentDataPath + "/players/" + Name + ".dat");
        bf.Serialize(file, baseInfo);
        bf.Serialize(file, inv);
        file.Close();
        
    }
    
    void OnDestroy()
    {
        Save();
    }

While this does throw warnings if the code gets called on a client it works for now. The isServer() isClient() and isLocalClient() seem to have issues giving accurate feedback.