✓ Accepted answer
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)
2 comments
The problem is that if the original mana value is small enough it will be increased but then you are rounding it back down to the original. So the value never changes. You should just keep the mana separate from the leaderstat.
How would I fix that?