Constantly Check a value while waiting

I would put a script where I started but I really have no idea how to go about this.

Basically I want to check if a player’s ATM was withdrawn while waiting on a 1.5x bonus for having cash in the atm. The bonus happens every 5 minutes you have money in the atm, however I want the timer to reset everytime a player takes out ALL the money in the ATM, not just some. I really don’t want anyone to write an entire script for me I just would like to see how to approach this.

Being able to withdraw money from an ATM means you have some sort of distinction between a bank account and on-person cash. You can set up the timer like so:

local INTERVAL = 5 * 60
local timerThread


local function startSingletonTimer()
    if timerThread then
        task.cancel(timerThread)
    end

    timerThread = task.defer(function()
        while true do
            task.wait(INTERVAL)

            -- Award bonus.
        end
    end)
end

local function onBalanceChanged(newBalance: number)
    if newBalance <= 0 then
        startSingletonTimer()
    end
end


startSingletonTimer()

balance.Changed:Connect(onBalanceChanged)
1 Like

Oh my gosh thank you. I was just wondering if I should set up a corountine or something but seriously thank you!

And after a coupling of tweaking I made it work

You gonna mark my answer as the solution? Lol

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.