diff --git a/src/lua_script.c b/src/lua_script.c
index 11ced70f25a7ed2f2728e4f3d9816b1191b3a736..b62fa675e2e7193da3a688d89d2f1cf377298a51 100644
--- a/src/lua_script.c
+++ b/src/lua_script.c
@@ -1500,8 +1500,11 @@ static void ArchiveTables(void)
 		{
 			// Write key
 			e = ArchiveValue(TABLESINDEX, -2); // key should be either a number or a string, ArchiveValue can handle this.
-			if (e == 2) // invalid key type (function, thread, lightuserdata, or anything we don't recognise)
+			if (e == 1)
+				n++; // the table contained a new table we'll have to archive. :(
+			else if (e == 2) // invalid key type (function, thread, lightuserdata, or anything we don't recognise)
 				CONS_Alert(CONS_ERROR, "Index '%s' (%s) of table %d could not be archived!\n", lua_tostring(gL, -2), luaL_typename(gL, -2), i);
+
 			// Write value
 			e = ArchiveValue(TABLESINDEX, -1);
 			if (e == 1)
@@ -1716,10 +1719,15 @@ static void UnArchiveTables(void)
 		lua_rawgeti(gL, TABLESINDEX, i);
 		while (true)
 		{
-			if (UnArchiveValue(TABLESINDEX) == 1) // read key
+			UINT8 e = UnArchiveValue(TABLESINDEX); // read key
+			if (e == 1) // End of table
 				break;
+			else if (e == 2) // Key contains a new table
+				n++;
+
 			if (UnArchiveValue(TABLESINDEX) == 2) // read value
 				n++;
+
 			if (lua_isnil(gL, -2)) // if key is nil (if a function etc was accidentally saved)
 			{
 				CONS_Alert(CONS_ERROR, "A nil key in table %d was found! (Invalid key type or corrupted save?)\n", i);