Script working on an object but not on another I downloaded a blend file from another user here with a script (for drivers) and a mesh + armature.
On the driver of said mesh it says Error:invalid Python expression. I couldn't get it to work for so long although it worked for the user that sent it to me. However after a while I figured out a really odd fix.The fix is to move the armature then ctrl+z after I do that, the driver no longer shows an error instead it shows slow python expression which is fine as long as it works I guess.
Now I tried applying the script to a personal mesh+armature I copied the same exact drivers+variable. I get the Error:invalid Python expression. I tried doing the same odd fix that worked for some reason on the other mesh+armature but it didn't work in this case. Here's the script
import bpy
from mathutils import Vector


def left(self, z_rotation, speed_low, speed_high):
    prev = self[&quot;prev_z&quot;]
    self[&quot;prev_z&quot;] = z_rotation
    delta = z_rotation - prev
    if delta &gt; 0:
        self[&quot;z&quot;] -= delta * speed_low
    elif delta &lt; 0:
        self[&quot;z&quot;] -= delta * speed_high

    return self[&quot;z&quot;]

def right(self, z_rotation, speed_low, speed_high):
    prev = self[&quot;prev_z&quot;]
    self[&quot;prev_z&quot;] = z_rotation
    delta = z_rotation - prev
    if delta &lt; 0:
        self[&quot;z&quot;] += delta * speed_low
    elif delta &gt; 0:
        self[&quot;z&quot;] += delta * speed_high

    return self[&quot;z&quot;]


bpy.app.driver_namespace[&quot;left&quot;] = left
bpy.app.driver_namespace[&quot;right&quot;] = right

Here's the driver of the mesh I downloaded from the other user.

And this is the driver I applied to my own mesh(the exact same thing)

I have no clue why this is happening the issue is just really weird and very frustrating.
Help would be immensely appreciated.
Custom properties not set
The driver script as is will throw an error if the custom properties &quot;z&quot; and &quot;prev_z&quot; are not set on the object.
Look for errors in the console.
Where does console output go
Add the appropriate custom properties to the object being driven for it to function as expected.
Note.
The object referred to as self in a driver is an  evaluated copy of the object.
Silly test script to ensure the original object has a custom property &quot;foo&quot; set from within the driver.
Returns the evaluated value of the custom property, if it exists, else 0.0.
from bpy.app import driver_namespace as dns

def test(ob):
    ob.original[&quot;foo&quot;] = ob.original.get(&quot;foo&quot;, 0.0)
    return ob.get(&quot;foo&quot;, 0.0)

dns[&quot;test&quot;] = test

copy and paste this driver into any object to create a &quot;foo&quot; custom property if one does not already exist.