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

Wait 3 seconds for an unchanged value, then gradually increase until its decreased again?

Asked by
Nikkulaos 229 Moderation Voter
5 years ago

Im working on making a stamina script where it always checks (in a span of 3 seconds) if the stamina has changed or not. If it hasnt, then it will gradually increase until it detects it is decreased again.

Here is my script:

while wait(.167) do
if c:FindFirstChild("Stamina") then
    local stamina = c:FindFirstChild("Stamina").Value
    spawn(function()
    delay(3,function ()
        if c:FindFirstChild("Stamina").Value == stamina and stamre == false then
            stamre = true
        else
            stamre = false
        end
    end)
    end)
    if stamre == true then
        c.Stamina.Value = c.Stamina.Value + 1
    end
end
end

And it isnt working too well. Can someone help fix it up for me? Thanks

1 answer

Log in to vote
0
Answered by
mc3334 649 Moderation Voter
5 years ago
local staminaValue = --Put value here

function Increase()
    --Code to increase stamina over 3 seconds here
end

lastStam = 0
while wait(3) do
    if staminaValue.Value >= lastStam then
        Increase()
    end
    lastStam = staminaValue
end

Short and simple. It checks if the stamina is going down every 3 seconds and if it's not then it will increase. If it is then it won't do anything. Comment if you need further assistance.

Ad

Answer this question