That error is caused by non-frame tables whose metatable __index is a frame. You can fix it by making your frame check more robust:
Code:
if val.IsProtected
and val.GetObjectType
and val.GetScript
and type(rawget(val, 0)) == "userdata"
and val:GetObjectType() == "CheckButton"
and val:IsProtected() then