Executing code when player leaves game

How would i execute code when a player leaves the game? I have no idea were to start