Well, all else aside, calling IsInInstance() in your aura filtering function, which is called once per active aura per UNIT_AURA event -- so, potentially
thousands of times per second in a raid -- is rather wasteful. Much better to keep track of that outside the function (create a separate frame if you need to) and refer to a variable inside.
As for the problem at hand, the caster unit can be -- and often is --
nil for auras applied by NPCs. Try changing this:
Code:
and not UnitPlayerControlled(caster) then
to this:
Code:
and not (caster and UnitPlayerControlled(caster)) then
Player-applied auras can also have a
nil caster, but only if they're applied by players who don't currently have a unit token, so while you're in an instance that shouldn't really be an issue.