Garry's Mod Wiki

Entity:SetHealth

  Entity:SetHealth( number newHealth )

Description

Sets the health of the entity.

You may want to take Entity:GetMaxHealth into account when calculating what to set health to, in case a gamemode has a different max health than 100.
In some cases, setting health only on server side can cause hitches in movement, for example if something modifying the player speed based on health. To solve this issue, it is better to set it shared in a predicted hook.

Issue Tracker: 3572

Arguments

1 number newHealth
New health value.

Example

Sets the entity's health to their maximum health.

Entity( 1 ):SetHealth( Entity( 1 ):GetMaxHealth() )
Output: The entity's health is now full.

Example

Deducts 50 points of health from the entity.

Entity( 1 ):SetHealth( Entity( 1 ):Health() - 50 )
Output: The entity now has 50 less health.