I am working on a map, and in this map's function I have a system that gives players who rejoin the map a /title message (rejoining meaning leaving the world then coming back). At first it seemed to be working fine, but I soon realized that occasionally I came on and had no score, so I wouldn't be /tp-ed to the spawn and I wouldn't get the message. I know I have no score because it doesn't work, then I leave and rejoin and then it does work.
These are the commands I am currently using:
/scoreboard objectives add leave minecraft.custom:minecraft.leave_game
/tp @a[scores={leave=1}] 0 5 0
/title @a[scores={leave=1}] title {"text":"Welcome back!","color":"aqua"}
/scoreboard players reset @a[scores={leave=1}] leave
It worked before. I have tried resetting the score only if the player is at the spawn, but it still does not work sometimes. It is crucial that I get this working every time. Is this a bug? Is there any workaround or a substitute, or am I just stupid?
EDIT
I have tested my map multiple times. These are my results:
-10 times I left the game normally, flying a distance away from the spawn before quitting. Each time was successful.
-10 times I opened to LAN before quitting. Nine times worked.
-5 times I reloaded and immediately quit. Each time failed.
-10 times I slightly edited and saved the function, five times in the game and five times not in the game. Each time was successful (and there were no synax errors).
-2 times I crashed the game by pressing F3 + T, making sure the game auto saved before I did. Not only did they fail but the next few logins after that failed too.
-I retested opening to LAN about 10 more times. I noticed it tended to fail the most when I was falling or when I immediately quit afterwards. At one point it took FOUR CONSECUTIVE LOGINS, without LAN active but after a LAN failure, to get my message.
Now I'm really scared about this issue.