-- Mana increase script. mana.Changed:Connect(function() while mana.Value < manac.Value do -- Manac is the capacity of mana one can have. wait(4) mana.Value = mana.Value + 10 end if mana.Value > manac.Value then mana.Value = manac.Value end
-- Basically a textbutton that increases exp and decreases mana when clicked, in the form of a remote event game.Players.PlayerAdded:Connect(function(player) game.ReplicatedStorage.ExpUp.OnServerEvent:Connect(function() local exp = player:WaitForChild("Leaderstats")["Exp"] local mana = player:WaitForChild("Mana") local manac = player:WaitForChild("Manac") if mana.Value >= 5 then exp.Value = exp.Value + 20 mana.Value = mana.Value - 10 end end) end)
the problem seems to be that ExpUp event changes the mana, which fires the whole mana regeneration part from the beginning, i would remove the mana.Changed() function as it only calls regeneration over and over every time the mana amount changes,
while mana.Value < manac.Value do end
could be replaced with:
while true do wait(4) if mana.Value < manac.Value then mana.Value = mana.Value + 10 if mana.Value > manac.Value then mana.Value = manac.Value end end end
hope this helps!