Update generator.lua

Added Brandon's protection code