I'm telling you - the problem is with the order of events. When using Local Storage you need to wait before doing anything else.
On start of layout -> read from Local Storage -> Wait for it to complete, only then compare variables!
When level is finished -> write to Local Storage -> Wait for it to complete, only then switch to another layout!
If you don't know how to organize this wait properly, you can simply wait 0.5-1 seconds, this should be enough.
.