Side note: if you are trying to add $MyNumber to $KeyAttributes, be aware the latter is a list of attribute names (“MyNumber”) and not attribute references ("$MyNumber"). The code should be:
$KeyAttributes=$KeyAttributes+"MyNumber";
If you looks at the notes added to your container, the key attributes table shows a ‘$MyNumber’. As no attribute of that name exists ($ is not a valid character in an attribute name) it looks like Tinderbox makes a best guess of a match and shows data for the attribute ‘MyNumber’.
Though Mark Anderson’s recommendation above is good, Tinderbox does automatically correct this common mistake and so it’s harmless.
The problem here is that, while Tinderbox guarantees that it will perform the OnAdd action at least once, Tinderbox is free to perform it more than once if it wants to. This simplifies all sorts of things: agents, undo/redo, and whatnot.
Suggestion: if this counter is being initialized at creation and then won’t change, test for whether you’re initialized already.