How to increase / decrease value in minecraft bossbar without entering a specific number 1.16.4

Hello I am working on my first minecraft map! But I don't know how to decrease / increase a number in the bossbar, without entering a specific number, instead, for example, incrementing by 1.

I am using version 1.16.4.


Solution 1:

Bossbars don't support math operations directly. Instead, you'll have to use a scoreboard to manage your bossbars.

I usually create an objective named bossbar for my bossbars, and use fake player names as descriptors.

scoreboard objectives add bossbar dummy [{"text":"Bossbar Values"}]

We need a repeating command block with the following command. This will make the bossbar use the scoreboard value.

execute store result bossbar minecraft:myBossbar value run scoreboard players get myBossbar bossbar

Then, all you need to do is increment the scoreboard and the value in the bossbar will change automatically. Use the following command to decrease bossbar by 5:

scoreboard players remove myBossbar bossbar 5