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

Any reason for stamina charge not working?

Asked by
Despayr 505 Moderation Voter
5 years ago

Instead of increasing the stamina by 10 every time, it increases by 10 the first time, then on the second it goes up by 30, then 70 and so on.

local Player = game.Players[script.Parent.Name]
repeat wait() until Player and Player:WaitForChild("Stamina") ~= nil
local MaxStamina = (100 + (1.5 * Player.Stats.Level.Value))

Player.Stamina.Changed:Connect(function()
while Player.Stamina.Value < MaxStamina do
        wait(0.5)
    Player.Stamina.Value = Player.Stamina.Value + (10)
    if Player.Stamina.Value > MaxStamina then
        wait(0.05)
        Player.Stamina.Value = MaxStamina
    end
end
end)

any better way of writing this? Or any suggestions on the problem?

0
Mind if you can post the error & the error line? HaloUlti 63 — 5y
0
there is no error .-. Despayr 505 — 5y

1 answer

Log in to vote
0
Answered by
herrtt 387 Moderation Voter
5 years ago

It is <= and >=, not < or >, second, you may use a while true do loop

wait()
local Player = game.Players[script.Parent.Name]
local MaxStamina = Player.Stats.Level.Value * 1.5 + 100

Player.Stamina.Changed:Connect(function()
    while true do
        MaxStamina = Player.Stats.Level.Value * 1.5 + 100
        if Player.Stamina.Value >= MaxStamina then
            Player.Stamina.Value = MaxStamina
            wait()
            break
        end
        wait(0.5)
        Player.Stamina.Value = Player.Stamina.Value + 10
    end
end)
0
Thanks but it had the same effect as my script did. I added a debounce and it works. Thanks anyways. Despayr 505 — 5y
Ad

Answer this question