Minecraft – How to you give a player a speed boost when they are sprinting in Minecraft

minecraft-commandsminecraft-java-edition

I'm trying to make a vanilla KitPvP server, and I want to make a kit that gives you normal walking speed, but when you are sprinting, you have a speed boost. Is that possible? If so, then how?

Best Answer

First, add an objective to keep track of whether players are sprinting:

/scoreboard objectives add IsSprinting stat.sprintOneCm

On a clock, give all players with a score in that objective of at least 1 the speed effect:

/effect @a[score_IsSprinting_min=1] speed 1 2

Then, also on the same clock, set the score to 0 for everyone so that the speed boost stops being applied when a player stops sprinting:

/scoreboard players set @a IsSprinting 0