Magic regen script not working. Why?

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

What doesn’t work? I have just tried it, and it works fine.

For some reason it does not work for me. When I use magic it does not regen at all it stays put. If you want I can show you.

1 Like

Sorry for the keyboard I couldn’t record on my laptop. But when you say a spell your magic decreases, but it will not increase after at all.

Is the script local or server, and where exactly is it?

And are there any errors in the output?

Server, inside of a starter character and there are zero errors.

Have you set the MaxMagic value to 1300?

When you join the game you have to choose a character. The MaxMagic ranges so yes, when you choose this character your MaxMagic will be set to 1300.

Waste your magic, then wait and check your magic value in the explorer while in game. Maybe it does get regenerated, you just don’t see it on the GUI

1 Like

I checked and it only shows the magic shown on the gui. Does not increase at all.

It’s weird because there are zero errors but seems to not work.

Oh wait, check if the regen script still exists when you play the game. Scripts inside startercharacter model sometimes get destroyed if you dont put them in StarterCharacterScripts

1 Like

Move the script into the ‘StarterCharacterScripts’ container.

1 Like

Can’t believe it was that simple ! Thanks!