Mana regens faster than it should, how do i fix?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Regen mana at a fixed rate

  2. What is the issue? Include screenshots / videos if possible!
    I’m using a Mana.Changed to detect if its < 100, so i can begin the regen process, but if a player uses more moves, it will regen faster. What else can i use?

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Going on discord and trying to get a response.

mana.Changed:Connect(function(property)
	while mana.Value < 100 do
		task.wait(1)
		print("adding mana")
		
		mana.Value += 5
		manaBar.Size = (manaBar.Size.X.Scale < 1) and UDim2.fromScale(manaBar.Size.X.Scale + .05, 1) or UDim2.fromScale(1,1)
	end
end)

Example Video

“but if a player uses more moves, it will regen faster. What else can i use?”

You’re logging the .Changed event every time mana changes, and your while loop is changing the mana; so something like:
Mana.Changed → While loop increases mana → Triggers new mana.Changed → starts another while loop → changes manna again → etc.

You need to check if mana is already in the regenerative process before you start the loop, an easy way to accomplish this would be adding a value that is representative of this.

Example w/ attributes:

mana.Changed:Connect(function(property)
	if mana:GetAttribute("Regenerating") == true then return end
	mana:SetAttribute("Regenerating",true)
	while mana.Value < 100 do
		task.wait(1)
		print("adding mana")
		
		mana.Value += 5
		manaBar.Size = (manaBar.Size.X.Scale < 1) and UDim2.fromScale(manaBar.Size.X.Scale + .05, 1) or UDim2.fromScale(1,1)
	end
	mana:SetAttribute("Regenerating",false)
end)