Unless I misunderstood you badly that’s the whole point of a local variable - it only persist when in scope, it does not retain its state between calls. Either pass data to the function or have it fetch a non-local variable.
If in doubt, show us an example.