Error in Script when Calling it?

Ok so I am very confused.

I wrote a script that builds a model for me, and it works fine, but now I’ve imported it and am trying to call it from an external file, but it crashes, telling me there is a “KeyError: ‘index out of range’”.

I know the error is coming from trying to merge too many or too few vertices into a face, but I can’t for the life of me figure out why it only happens when i call the script from another file.