Retrieve data from local storage works only after second click

Hi,

please refer to below blocks image .
I have a function “getSelectPlayer” that fetches a value from local storage and should returns this value.
I am calling this function from button click event.
from first click I get “undefined” coming back from the function
second click brings the value I was supposed to get in the first click.
third click brings the value I was supposed to get in the second click, etc…

Any idea why this happens?

Thanks

Set a variable like :
Each time the user click set variable to variable + 1

And then set if variable = 2 then do …

And don’t forget to set the variable to 0 after that

Hope it helps !