How to find someone's personal best? (fastest time in a race?)
Use scoreboard operations
I assume you also have the time stored in a non-formatted scoreboard, e.g. in ticks. Let's call that objective time
. If not, see below.
Make another dummy scoreboard objective called best
, and initalize it to 0, e.g. by running
/scoreboard players add @a best 0
When a player finishes the race, mark him in some way, e.g. by assigning a tag (I'll use tag=finished
). Then simply run
/execute @a[tag=finished] ~ ~ ~ scoreboard players operation @a[c=1] best < @a[c=1] time
The <
operator will assign the lesser score of best
and time
to best
. The execute
makes sure that both targets of the scoreboard command are the same player.
You can turn best
into bestminute
and bestsecond
the same way you converted time
into the display stats.
Converting times to a single number
If you don't have time stored as a single continuously increasing number, you can use scoreboard players operation
commands to turn your dispminute
and dispseconds
scores into one. Set up the new objective, and store the number 60 in a fake player (called #SIXTY):
/scoreboard objectives add time dummy
/scoreboard players set #SIXTY time 60
Now, set up a repeat/chain line and run.
/scoreboard players set @a time 0
/execute @a ~ ~ ~ /scoreboard players operation @a[c=1] time += @a[c=1] dispminutes
/execute @a ~ ~ ~ /scoreboard players operation @a[c=1] time *= #SIXTY time
/execute @a ~ ~ ~ /scoreboard players operation @a[c=1] time += @a[c=1] dispsecond
This will first reset the time score for every player. Then, the players' scores in dispminutes
will be added to time
, and multiplied by 60. Lastly, dispseconds
is added to time.