05-13-2015, 06:40 AM
Due to multithreading it cannot be so simple - the "player disconnecting" will be processed by a different thread running in parallel to your plugin, so the Player object can become invalid right after the IF has checked it to be valid, but before the --code executes:
-- Player is currently connected, PlayerObj is a valid object if (PlayerObj) then -- Player disconnects right here -- PlayerObj becomes invalid PlayerObj:SendMessage("...") -- fails - PlayerObj invalid, despite the condition endThis is the price we pay for being multithreaded - we do need to use the DoWith and ForEach calls. Those guarantee that the object is valid as long as the callback is executing (but, again, you cannot store the object to be used later after the call).