How exactly are you checking if your event is being queued? And how are you checking if the pk table is being reset?
Do keep in mind when you do things like:
_G.pk = {}
local pk = _G.pk
You do not have 2 tables, you instead have 2 variables that point to the same table. Any changes made using one variable to the table happens to the other variable's table simply because they are the same table.
This makes things like the following redundant (You are setting _G.pk to itself since pk and _G.pk both point to the same table):
table.insert(pk,key)
_G.pk = pk
These things really wouldn't keep the programming from working, it is just useful things to know.
As best I can tell by reading through the code, the pk table is never actually reset. Whenever you try to reset the table you create a new local pk table (this is different from the local pk table at the top of your code), and set _G.pk to it. However, whenever you receive a new event you set _G.pk equal back to the local pk defined at the top of the code causing it to have all of the previous entries.
Edited by valithor, 16 January 2017 - 10:38 PM.