I don't have the answer to your specific question at the moment, but I noticed several lines like this in your code:
Code:
local f = getglobal(framename)
The
getglobal function was deprecated years ago; this means it is not supported, and it is strongly recommended that you do not use it. Instead, you should use a simple table lookup in the "magic" table _G, which contains the global namespace:
Code:
local f = _G[framename]