You are currently telling the object to close its output when an item exits while at least 13 items are inside the object.
What you need to do is use the output count of the object as the condition.

The "%" is the modulo operator (rest of division). With this setting the object will close its output if the remainder of the total output divided by 13 is equal to 12. Meaning when the 13th, 26th, 39th, ... item is about to exit.
Note: If the items are transported by a task executer you must be aware of the delay between an item being released and the item actually leaving the object. Closing the output after an item is released will not hold it and the transport task will still be completed. In this case you would need to close the output when the 13th item is released, which is trickier, because there is no trigger option for this. One option would be to put the code to close the output into the transport reference field.