Okay.. first of all.. it should be hooked into an event and it should be executed on the "ADDON_LOADED" event so that we're sure it does not try to update nUI's default layout tables until after we know that have been loaded and initialized and before any user customization is applied which occurs in the "VARIABLES_LOADED" event.
Second, and this may sound silly... but did you ever give "skinName" a value?
Code:
local skins =
{
[1] = "PlayerTarget",
[2] = "HealthPower",
};
for i in pairs( skins ) do
local skinName = skins[i];
if nUI_UnitSkins[skinName] then
nUI_UnitSkins[skinName].elements["Level"] = myLevelBlock;
end
end