/scoreboard objectives add time dummy
Adds a score called "dummy": this score will be used to change the highscore
/scoreboard objectives add highscore dummy
Adds a score called "highscore": this one will be changed with the scoreboard command
/scoreboard players operation @a highscore > @a time
This command changes "highscore"'s value in "time"'s value, but only if "time"'s value is higher than "highscore"'s value: if you want the score to change when "time"'s value is lower, just replace the ">" with "<"
/scoreboard players add @a time 1
This command adds 1 to the score
/scoreboard players set @a time 0
This score is used to reset the score. If you want to reset the hgscore, just replace "time" with "highscore"