Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

health regeneration stop and or edit script?

Asked by 7 years ago
Edited 7 years ago

is there a way to stop the health generation until like a sertain 'lvl' like

if game.Players.LocalPlayer.leaderstats.Level.Value >= 15  then
-- health regen + 100 every second
end

and if you are like below lvl 15 then you get 0 health per second. is there a way to edit the health script like that ?

if there is allot or something missing just comment and ill edit the question.

2 answers

Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

When you spawn a script is created in the character called "Health" which is where the players health regeneration is done.

There are multiple ways of doing this but the way I would do this is to delete the Health script when the character spawns.

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(charModel)
        charModel:WaitForChild('Health'):Destroy() -- deletes the script
    end)
end)

We can then check the players level ect then connect a new function which will be similar to the Heath script.

This is just an example server script

local function healthRegen(incAmount, hum)
    local deb = false

-- we return a new function to be used in our health regenoration
    return function()
        -- debounce
        if deb then return end
        deb = true

-- we pick the lowest value
-- hum.Health + (incAmount * wait(1)) we add to the health the inc amount * the time waited
        hum.Health = math.min(hum.MaxHealth, hum.Health + (incAmount * wait(1))

        deb = false
    end
end

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(charModel)
        charModel:WaitForChild('Health'):Destroy() -- deletes the script

        local hum = charModel:WaitForChild('Humanoid')

        if [ check the players level here] then
            hum.HealthChanged:Connect(healthRegen([some value], hum))
        end     
    end)
end)

I hope this helps, please comment if you do not understand how / why this script works.

0
I personally think yours is over-complicated. But then again we all script in our own way. It's just so long lol animelover6446 41 — 7y
Ad
Log in to vote
-2
Answered by 7 years ago

Tell me if this helps at all

local Player = game.Players.LocalPlayer
local leaderstats = Player:FindFirstChild("leaderstats")
local Level = leaderstats:FindFirstChild("Level")

if Level.Value >= 15 then
while true do
wait(1) --Change this to what you consider a second
Player.Humanoid.Health = Player.Humanoid.Health + 100 --Change this to how much they regen

end
end
0
You don't explain your code, and I'm pretty sure this won't work properly. OldPalHappy 1477 — 7y
0
I'm assuming he knows what he is doing a bit. I tested it and it worked fine for me. He just has to set it to a function etc. animelover6446 41 — 7y

Answer this question