This question already has an answer here:

I am working on a game that uses commands in such a way that players disconnecting then reconnecting could break the commands. I was wondering if there is a way to detect when players join the game in 1.13.2 and run a command to give them an item. When I researched this, I found solutions for older versions using /testfor or stat.leaveGame, but those seem to be outdated in 1.13. If someone could show me the commands to use as well as the layout for command blocks/redstone that would be great. It can be for the second time they join only, or for all times that they do. Thanks

marked as duplicate by Gigazelle, galacticninja, Joachim, Virusbomb, Batophobia yesterday

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Questions on Stack Exchange should not be re-asked just because the current answers are outdated. – pppery 2 days ago

the way you're looking for that involved testfor and stat.leavegame would now be best suited by using execute and minecraft.custom:minecraft.leave_game. essentially, you would do all the same things you would with testfor, except no redstone is needed now. when you use execute, you can tell the game to run it if they have a leave game score of 0 (or whatever you need to do for it) by doing something like below;

/execute at @a as @s if score @s <scoreName> matches 0 run <command>

you could also do a different one, with this technique, for a command you want to run if their leave game score is a certain about (or higher than a certain amount);

/execute at @a as @s if score @s <scoreName> matches <value> run <command>

for <value>, to make it run for everything up to that value or everything that value and greater, use ..<value> or <value>.., respectively.

  • 2
    Thanks! this was extremely helpful! – Amphibiangamer10 Apr 21 at 3:14
  • no problem! if you need anything else, don't be afraid to ask :D – EarthToAccess Apr 21 at 4:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.