1

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?

3 Answers 3

1

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```

0

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.

3
  • Thanks for the reply, hopefully either a method can be added into the game or someone can come up with something !
    – Wiam
    Commented Jul 12, 2019 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={…}]. Commented Jul 12, 2019 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
    Commented Jul 12, 2019 at 17:25
-3

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.

2
  • 3
    This question is asking how to detect a player quitting with a command block. Your answer doesn't answer the question.
    – pppery
    Commented Aug 10, 2019 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
    Commented Aug 10, 2019 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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