I have a score named "DirtCount", I want to add the number of dirt in my inventory to the score.
I found this command that sets the score to the number of dirt :

/execute as @p store result score @s DirtCount run clear @p minecraft:dirt 0

But that is not what I want, I want to add, not set, how to do it ?


Just overwrite a separate scoreboard and add them together. Assuming you have a TempDirtCount objective (create it with /scoreboard objectives add TempDirtCount dummy if not), you can do:

/execute as @p store result score @s TempDirtCount run clear @p minecraft:dirt 0
/scoreboard players operation @p DirtCount += @p TempDirtCount

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.