Minecraft command blocks, how do i link my boss bar to my player health [closed]

i created a scoreboard called health and i also created a boss bar named health, i'm not sure how to link the boss bar and the players health using command blocks


Solution 1:

You don't need a scoreboard objective.

Set the max value of the bossbar to 20:

/bossbar set minecraft:health max 20

Make it visible to you:

/bossbar set minecraft:health players @s

Run this command in a repeating command block:

execute store result bossbar minecraft:health value run data get entity @p Health