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

Setting Players to Full Health

Setting Players to Full Health

Jun 14 2019, 4:46 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.

local healPart = Workspace.HealPart
function onTouched(otherPart)
	local human = hit.Parent:FindFirstChild("Humanoid")
	if human then
		human.Health = human.MaxHealth
	end
end
healPart.Touched:Connect(onTouched)

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