That's the spot it's complaining about. Line 69 in function
BattleDex.RecordPet(). The only line there that would generate that error (there are other operations like it, but it would throw a different error generating the second key) is this.
Code:
_G.BattleDexDB.pets[species] = _G.BattleDexDB.pets[species] or {};
The error is specifically saying
species is
nil.
PS: The theory was about the enemy team having
less than 3 pets. The only other explanation is if
BattleDex.RecordBattle() is running before pet data is available.