/

/attribute

op 2Entities

/attribute reads and writes the numeric attributes behind an entity — health, speed, damage, knockback resistance, reach. In 1.21.2 every attribute id lost its generic. and player. prefix, so generic.max_health became minecraft:max_health. Using the wrong spelling for your version is the usual reason the command fails.

Command1 to fix
17
/attribute @e get
  • Attribute is required.
Press C to copy
All entities
@e

Who or what the command applies to

Attribute is required.

optional

Examples

  • 20 hearts
    /attribute @s minecraft:max_health base set 40
  • Faster walking
    /attribute @s minecraft:movement_speed base set 0.2

Common questions about /attribute

Why does generic.max_health not work any more?

It was renamed in 1.21.2. Use minecraft:max_health on 1.21.2 and later, and generic.max_health before that. Every attribute lost its generic. or player. prefix in that update, not just this one.

How do I give a player 20 hearts?

Health is measured in half-hearts, so 20 hearts is 40. /attribute @s minecraft:max_health base set 40, then heal them so they actually reach the new maximum.

What is the difference between base set and a modifier?

base set changes the underlying value permanently. A modifier is a named adjustment layered on top that can be removed later by its id, which is what equipment and potions use.