Ad
Log in to vote
0

How can I stop regeneration over 80 health?

Asked by 4 months ago

How can I make a script that does this: when a player's health goes under 80, It doesn't regen to 100, but 80 instead. If the health is above 80, then it will regen to 100. (You may be able to do to this by changing the 'Health' script inside a player's model).

Thanks

2 answers

Log in to vote
0
Answered by 4 months ago
Edited 4 months ago

Make sure this is a Server Script, and it's named Health, and it's located inside StarterCharacterScripts.

-- Gradually regenerates the Humanoid's Health over time.

local REGEN_RATE = 1/100 -- Regenerate this fraction of MaxHealth per second.
local REGEN_STEP = 1 -- Wait this long between each regeneration step.

--------------------------------------------------------------------------------

local Character = script.Parent
local Humanoid = Character:WaitForChild('Humanoid')

--------------------------------------------------------------------------------

while true do
    while Humanoid.Health < 80 do
        local dt = wait(REGEN_STEP)
        local dh = dt*REGEN_RATE * Humanoid.MaxHealth
        Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth)
    end
    Humanoid.HealthChanged:Wait()
end

Upvote / Accept if this helped you. :)

Ad
Log in to vote
0
Answered by
popeeyy 252 Moderation Voter
4 months ago

First, you may want to add something to your game like a health regen pad so it doesn't infinitely give health, otherwise they're "godded".

Here's a script that may work if they step on a regen pad:

--Health REGEN PAD
--Parent is regen pad

local db = false

script.Parent.Touched:connect(function(part)
    if part.Parent and part.Parent:FindFirstChild'Humanoid' and not db then
        db = true
        local health = part.Parent.Humanoid.Health
        if health >= 80 then
            health = 100
        else
            health = 80
        end
        wait(1)
        db = false
    end
end)

The db variable is debounce so it doesn't give them too much health by just standing on the pad.

0
if mean automatic regeneration. Thanks anyway. :) blocky010101 4 — 4mo
0
*i not if blocky010101 4 — 4mo

Answer this question