1 | -- Mana increase script. |
2 | mana.Changed:Connect( function () |
3 | while mana.Value < manac.Value do -- Manac is the capacity of mana one can have. |
4 | wait( 4 ) |
5 | mana.Value = mana.Value + 10 |
6 | end |
7 | if mana.Value > manac.Value then |
8 | mana.Value = manac.Value |
9 | end |
01 | -- Basically a textbutton that increases exp and decreases mana when clicked, in the form of a remote event |
02 | game.Players.PlayerAdded:Connect( function (player) |
03 | game.ReplicatedStorage.ExpUp.OnServerEvent:Connect( function () |
04 | local exp = player:WaitForChild( "Leaderstats" ) [ "Exp" ] |
05 | local mana = player:WaitForChild( "Mana" ) |
06 | local manac = player:WaitForChild( "Manac" ) |
07 | if mana.Value > = 5 then |
08 | exp.Value = exp.Value + 20 |
09 | mana.Value = mana.Value - 10 |
10 | end |
11 | end ) |
12 | 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,
1 | while mana.Value < manac.Value do |
2 | end |
could be replaced with:
1 | while true do |
2 | wait( 4 ) |
3 | if mana.Value < manac.Value then |
4 | mana.Value = mana.Value + 10 |
5 | if mana.Value > manac.Value then |
6 | mana.Value = manac.Value |
7 | end |
8 | end |
9 | end |
hope this helps!