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

How to make magic regen script work using roblox's health script?

Asked by 2 years ago

I tried using roblox’s health script to create a magic regen script using value’s but it seems to not work. Why is that?

local MAGICREGEN_RATE = 1/100 -- Regenerate this fraction of MaxHealth per second.
local MAGICREGEN_STEP = 1


--------------------------------------------------------------------------------
local Character = script.Parent
local magic = Character:WaitForChild'Magic'
--------------------------------------------------------------------------------


while true do
    while magic.Value < magic.MaxMagic.Value do
        local dt = wait(MAGICREGEN_STEP)
        local dh = dt*MAGICREGEN_RATE*magic.MaxMagic.Value
        magic.Value = math.min(magic.Value + dh, magic.MaxMagic.Value)
    end
    magic.Value.Changed:Wait()
end
0
Can I ask what 'magic' is? Is it a NumberValue? Leamir 3138 — 2y
0
obviously yea User#47934 5 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

First of all, you could do:

while true do
    if magic.Value < magic.MaxMagic.Value then

    end
end

instead of:

while true do
    while magic.Value < magic.MaxMagic.Value do

    end
end

I don't know the problem but this works:

local MAGICREGEN_RATE = 1/100 -- Regenerate this fraction of MaxHealth per second.
local MAGICREGEN_STEP = 1


--------------------------------------------------------------------------------
local Character = script.Parent
local magic = Character:WaitForChild("Magic")
--------------------------------------------------------------------------------


while true do
    if magic.Value < magic.MaxMagic.Value then
        wait(0.01)
        local dh = MAGICREGEN_STEP * MAGICREGEN_RATE * magic.MaxMagic.Value
        magic.Value = math.min(magic.Value + dh, magic.MaxMagic.Value)
    end
end
Ad

Answer this question