I am trying to detect when a player has quit the server, I have the scoreboard to detect when a player quits:

/scoreboard objectives add quit minecraft.custom:minecraft.leave_game

However, the rest of my command blocks only activate when the player re-joins the world. I am trying to set the player deaths to 3 when they quit:

scoreboard players set @a[scores={quit=1}] deaths 3

scoreboard players set @a[scores={quit=1}] quit 0

Is there any way to fix this?


I used something similar to add a welcome back message to a server I play on, and unfortunately, once the player leaves the game, their score cannot be incremented until they rejoin.

I tried finding a solution to this by using an ID system and checking for who is not online but marked as online in a dummy objective (using 1 and 0 as online and offline flags) and setting their here score to 0, but because you can't test for the scores of players who are not online without explicitly naming them, the system does not work.

Hopefully someone else can come up with a different solution to your problem, however.

| improve this answer | |
  • Thanks for the reply, hopefully either a method can be added into the game or someone can come up with something ! – Wiam Jul 12 '19 at 1:46
  • You almost had it. If you have an ID system, you just need to loop over the numbers and check if they're all still there (using execute if entity @p[scores={…}]. – Fabian Röling Jul 12 '19 at 16:24
  • That determines if they're online or not but not if they've just left. Edit: I'm dumb. I'll go add that in when I get home later today. – Nik3141 Jul 12 '19 at 17:25

Yes, there is a way to do this.

You can use scoreboard operations to do it. You need to have a dummy entity with the global timer. Every once in a while you'd pick a random player to test. Start by copying the player's score into a temporary score using the = operation: scoreboard players operation temp @s = timer @s. Then subtract the global timer score from the temporary score using the -= operation. If the resulting score is 0, then the timers are in sync. To sync the timer, simply copy the global timer score into the player's timer score (again using the = operation).

I think the following should work:

/scoreboard objectives add Local_Timer dummy
/scoreboard objectives add Global_Timer dummy
/scoreboard objectives add Temp_Timer dummy

execute store result score Global Global_Timer run time query gametime
scoreboard players add @a Local_Timer 1
execute as @a run scoreboard players operation @s Temp_Timer = @s Local_Timer
execute as @a run scoreboard players operation @s Temp_Timer -= Global Global_Timer
execute as @a[scores={Temp_Timer=..-1}] run say hi
execute as @a[scores={Temp_Timer=..-1}] run scoreboard players operation @s Local_Timer = Global Global_Timer```

| improve this answer | |

You should try to not use the scoreboard, and instead try joining the server and when a player quits the game, a yellow message will appear in the top left corner of the screen, saying [gamertag] has left the game.

| improve this answer | |
  • 2
    This question is asking how to detect a player quitting with a command block. Your answer doesn't answer the question. – pppery Aug 10 '19 at 14:55
  • 3
    Please take a bit more time to properly read questions and understand them. That will make for better answers, which will help your interactions here at Arqade. – Frank Aug 10 '19 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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