Health regeneration points

How can I add a part that regenerate your healt when it is crossed ?

Hook the Touched event of the part to a function. That function should have the object that touched the part as an argument. In this instance, let’s call it Part. Have it check the parent and check if it has a Humanoid with FindFirstChildOfClass(). If it does, have the humanoid’s health be added by a set amount. You can do this through the Humanoid’s function, TakeDamage() and input a negative number or use Humanoid.Health = Humanoid.Health + x, with x being your designated number.

You could also put a limit on it with a boolean, if that suits your fancy.

Too confusing? Here’s some pseudocode.

local mainPart = workspace.Part

local canHeal = true
local cooldown = 5
local healAmount = 15

local function healOnTouch(part)
    if part and part.Parent then
        local Humanoid = part.Parent:FindFirstChildOfClass("Humanoid")
        if Humanoid then
            if canHeal then
                canHeal = false
                Humanoid.Health = Humanoid.Health + healAmount -- or Humanoid:TakeDamage(-healAmount)
                wait(cooldown)
                canHeal = true
            end
        end
    end
end

mainPart.Touched:Connect(healOnTouch)
1 Like

If looking for additional information along with what the other user has brought up, there is a guide that demonstrates what you mentioned in your question along with additional features on this ROBLOX Dev Wiki page.

1 Like