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
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