Library function varible seems to not increment

I wrote some local functions that work similarly to this, but when i changed it to a library function for use later, the output does not appear to increment and decrement the same way

Imgur

That is the function that is from the library

This is the function that originally worked, note, it uses CurrentRightInput and that is NOT a variable local to this function, that is the only difference as far as i can see, but i don’t know if it should be acting differently
Imgur

I also have this issue. It increment only for once. Not for second time.

Local variables do not retain their value once the function has completed. So if you have a local variable inside a function that starts at a value of 1 and it gets incremented to 2 by the completion of the function, the next time you call the function it will have reverted back to its default value of 1. If you want it to retain the value as it is changed in the function during subsequent function calls you will need to make it a global variable. The purpose of a “local” variable is that it doesn’t clutter up the rest of the code. If you only need to have a variable for use internally within a function then a local variable is fine. If you need it to be used outside the function and it will not be passed directly from one function to another so that its value is always maintained somewhere then you need to use a global variable.

Yes I figured it out. I thought local variables just can not be used with blueprint communication (for example get all actors of class or etc.) but can store some values. But I learned, they dont :smiley: