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
4 years ago
 -- 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)
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 — 4y

1 answer

Log in to vote
0
Answered by 4 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,

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!

Ad

Answer this question