Skinstashery
Roblox
Home / Roblox / Studio script library / Heal pad
RB-004

Roblox heal pad script

A part that gives health back to players who stand on it.

Script type
Script
Where it goes
Inside the Part
Category
Hazards and pads

For your own game in Roblox Studio. Not for use in other people's games.

The code

-- Heal pad: restores health to a character that touches the part.

local HEAL_AMOUNT = 25    -- health given each time
local COOLDOWN = 1        -- seconds between heals for the same character

local part = script.Parent
local recentlyHealed = {}

part.Touched:Connect(function(hit)
	local humanoid = hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid")
	if not humanoid or humanoid.Health <= 0 then
		return
	end
	if recentlyHealed[humanoid] then
		return
	end

	recentlyHealed[humanoid] = true
	humanoid.Health = math.min(humanoid.MaxHealth, humanoid.Health + HEAL_AMOUNT)
	task.wait(COOLDOWN)
	recentlyHealed[humanoid] = nil
end)

How to set it up

  1. Insert a Part and colour it green so players know what it is.
  2. Add a Script inside the Part.
  3. Paste the code into the Script.
  4. Play, take some damage, and step on the pad.

Change it

More in Hazards and pads

All Roblox scripts

More Roblox tools