# Retrieve data from local storage works only after second click

**URL:** https://community.thunkable.com/t/retrieve-data-from-local-storage-works-only-after-second-click/47232
**Category:** Questions about Thunkable X
**Created:** [September 17, 2018, 11:36am UTC](https://community.thunkable.com/t/retrieve-data-from-local-storage-works-only-after-second-click/47232 "2018-09-17T11:36:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![LGreen](https://avatars.discourse-cdn.com/v4/letter/l/ed655f/32.png) [@LGreen](https://community.thunkable.com/u/LGreen)
#### Post date: [September 17, 2018, 11:36am UTC](https://community.thunkable.com/t/retrieve-data-from-local-storage-works-only-after-second-click/47232/1 "2018-09-17T11:36:25Z")

</div>

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?

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/d/fdb29d2c0b0058f2865c813ab2ced0cfc47d8396.png)

Thanks

---

<div class="post-metadata">

### Author: ![AcrobatEpee](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/acrobatepee/32/26336_2.png) [@AcrobatEpee](https://community.thunkable.com/u/AcrobatEpee)
#### Post date: [September 17, 2018, 2:07pm UTC](https://community.thunkable.com/t/retrieve-data-from-local-storage-works-only-after-second-click/47232/2 "2018-09-17T14:07:18Z")

</div>

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 !

---

<div class="post-metadata">

### Author: ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)
#### Post date: [November 8, 2024, 11:55am UTC](https://community.thunkable.com/t/retrieve-data-from-local-storage-works-only-after-second-click/47232/3 "2024-11-08T11:55:33Z")

</div>


