setCooldown

function tryToUseCooldown()

    local cd_ready = helper.checkCooldown('myCd');  --works with coroutines
    --this accounts for the cd variable being from another coroutine.
    
    local cd_timeLeft = helper.cooldownTimeLeft('myCd'); --works with coroutines
    
    
    if cd_ready == false then
        log('you can\'t use this yet... until another ' .. cd_timeLeft .. ' seconds has passed');
        return;
    end
    
    log('it worked. now consume the cooldown.');
    
    helper.setCooldown('myCd'); --works with coroutines
    --set it on cooldown for the 15 seconds again...
end

myCd = {}; -- global variable;

return function()

    myCd = helper.createCooldown(16, true); 
    --create a new cooldown for 15 seconds, and it starts as ready = true
    --the name of the global variable is 
    
    tryToUseCooldown(); -- it worked!
    tryToUseCooldown(); -- can't use this yet...
    wait(16);
    tryToUseCooldown(); -- it worked!
end

Last updated