It probably can't find the objects, so it will exit when you try to access objBkg because it is null.. Make sure you turn on the debug monitor for scripting option so you can see the error messages it returns.
In the loop code you provided, it is looking for an object called "Kreds_bkg1" (no space), and in your example without the loop it is looking for "Kres_bkg 1" (with a space).
#XPression