Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

For some reason, this mana script I created isn't working the way it's intended, can someone help?

Asked by
Knqe 23
5 years ago
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)
03game.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)
12end)
0
Basically, whats going on is, every time I click the button, it adds on a new command to increase the mana every 4 seconds, and I only want this command to be done once. Knqe 23 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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,

1while mana.Value < manac.Value do
2end

could be replaced with:

1while 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
9end

hope this helps!

Ad

Answer this question