BLOXBUILDS
Discord
Back
COMBAT

Healing Pad / Damage Zone

Paste as a Script inside a pad. Set the Mode attribute to Heal or Damage. A character standing on the pad gains or loses health every half second.

-- Paste as a Script inside a pad.
-- Set the part attribute Mode to "Heal" or "Damage".

local AMOUNT = 10
local INTERVAL = 0.5

local pad = script.Parent
if not pad or not pad:IsA("BasePart") then
	return
end

local mode = pad:GetAttribute("Mode")
if mode ~= "Heal" and mode ~= "Damage" then
	mode = "Damage"
end

local standing: { [Humanoid]: boolean } = {}

pad.Touched:Connect(function(hit)
	local humanoid = hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid")
	if not humanoid or standing[humanoid] then
		return
	end

	standing[humanoid] = true
	while humanoid.Parent and humanoid.Health > 0 do
		local stillHere = false
		for _, touching in ipairs(pad:GetTouchingParts()) do
			if touching:IsDescendantOf(humanoid.Parent) then
				stillHere = true
				break
			end
		end
		if not stillHere then
			break
		end

		if mode == "Heal" then
			humanoid.Health = math.min(humanoid.MaxHealth, humanoid.Health + AMOUNT)
		else
			humanoid:TakeDamage(AMOUNT)
		end
		task.wait(INTERVAL)
	end
	standing[humanoid] = nil
end)