Problem Regarding Minor Regen Script

I’m currently working on a mana system for a game, and I have most of it completed, but I’ve run into a small problem. Every player has a value for mana, and this is the script inside it:

if script.Parent.Value < 100 then
    repeat wait() script.Parent.Value = script.Parent.Value + .1 until script.Parent.Value >= 100
end

The problem with this is that once an ability is used and the available mana is reduced, then it doesn’t increase anymore - it just stays at the value that’s left after a mana cost has been withdrawn. I’m sure I’m just missing a small step, but I can’t figure out how to fix it.

Here’s a short clip of what I’m describing:
https://gyazo.com/7939b00cbdc2ab473ce988ea9f29a18b

1 Like

Can you provide more code that is relevant to this topic? Using this one line you really can’t tell what’s going on.

This is the only code that I need help with - the rest of it doesn’t have anything to do with regenerating mana, they simply subtract mana from the NumberValue whenever an ability is used.

Try adding a while true do loop on that if statement.

while wait() do
 if script.Parent.Value < 100 then
    repeat wait() script.Parent.Value = script.Parent.Value + .1 until script.Parent.Value >= 100
  end
end

You can connect script.Parent.Changed to that function so it’ll refill each time the value is lowered. You’ll have to make sure to add a check so that it doesn’t keep increasing faster and faster, sort of like a denounce.

Thanks, this solved it, everything’s working properly now.