I just made my mana class from NumberValue into IntValue, and now the regen script broke?
New Regen script with round
P = script.Parent.Parent local target = script.Parent.Parent local manaValue = target.bin.Mana while true do wait(1) local newValue = manaValue.Value + (manaValue.Value / 120) manaValue.Value = math.floor(newValue + 0.5) end
Old Regen script
while true do wait(1) P.bin.Mana.Value = P.bin.Mana.Value + (P.bin.MaxMana.Value / 120) end
What is happening is your entire calculation is being rounded. This means that your calculation will be pointless if manaValue.Value / 120
is less than 1, since it will be rounded down and be equivalent to no change at all!
We can fix this by just rounding up every time, so we still notice an increase in mana every second rather than waiting for manaValue.Value / 120
to go above 1.
Also, since this is mana regeneration, I am guessing that you want to cap it at the original mana value. We will need to add additional code to do this, and we can simply just check if the new calculation will pass the original mana value and correct it accordingly.
Here is what that would look like...
local target = script.Parent.Parent local manaValue = target.bin.Mana local originalMana = manaValue.Value manaValue.Changed:connect(function(value) if value < originalMana then local result = value + math.ceil(value / 120) if result > originalMana then result = originalMana end manaValue.Value = result end end)