This is a script that is supposed to regenerate Magic over time for the player. The value for Magic has already been established for the player in the leaderstats. **This script executes fine, but there is a problem: When the player levels up, the Magic continues to regenerate at the same rate rather than increasing at a rate to accommodate the new level of the player. ** The script does not recognize that the level has changed, therefore, it continues to regenerate at the same rate, unless the player resets. Why is this?
--This script is in the StarterGui
player = script.Parent.Parent
leaderstats = player.leaderstats
level = script.Parent.Parent.leaderstats.Level.Value --When this value changes, the script does not recognize it, so the Magic continues to regenerate at the same rate. Why?
magic = leaderstats.Stats.Magic
maxmagic = (20+level*2) --The problem with recognizing the level also causes a problem here; when the player levels up, this value increases as well, because the value of the new level factors into this equation. But since the script doesn't recognize the level, this doesn't change either. Now, when the Magic regenerates, it stops here, short of the new max.
speed = leaderstats.Stats.MagicSpeed.Value*.05
rate = math.ceil(maxmagic*.045)
while true do
wait()
if magic.Value < maxmagic then
wait(speed)
magic.Value = magic.Value + rate
elseif magic.Value > maxmagic then
magic.Value = maxmagic
end
end

2 comments
Thank you very much, this worked! Now I get it!
Np :D