PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Setting Players to Full Health

Setting Players to Full Health

Jun 25 2018, 1:23 PM PST

Problem

You want a part to heal a player when they touch it.

Solution

Set the Humanoid’s Health property to its Humanoid/MaxHealth|MaxHealth property.

Workspace.HealPart.Touched:connect(function(hit)
        local hum = hit.Parent:FindFirstChild("Humanoid")
        if hum then
                hum.Health = hum.MaxHealth
        end
end)

Discussion

We connect the Humanoid/Touched|Touched event to a part in the Workspace called “HealPart”. We then safely index a Humanoid from the parent of the object which touched the healing part. If this Humanoid exists, then we set its Humanoid/Health|Health to the total amount of health it can have, which is contained within its Humanoid/MaxHealth|MaxHealth property.

Tags:
  • powerup
  • health
  • humanoid
  • script