API CreateFrame:
Lua Code:
newFrame = CreateFrame("frameType"[, "frameName"[, parentFrame[, "inheritsFrame"]]]);
The second argument is frame name not frame parent.
And if a visible frame is not a child of UIParent, it won't change it's visibility with UIParent(Alt+Z).
try
Lua Code:
local bg = CreateFrame("Frame", nil, UIParent);
or
Lua Code:
local bg = CreateFrame('Frame', nil, UIParent)
whatever...