I recommend having a look here [How-to] Adapt your script to OneSync and fix your issues