0

As the title suggests I am playing a random sound based on a tag in a command. the problem is, if someone runs this command multiple times, it just plays the sound, even if the other one has not finished yet, besides that it works as intended. be gentle, Im extremely new to all of this (less than a month)

function playRandomFromTag (tag) {
    var sfxArr = [];
    var sfxKeys = Object.keys(soundList);
    sfxKeys.forEach( (sfx ) => {
        if (soundList[sfx].tags === tag) {
            sfxArr.push(soundList[sfx].loc);
        }
    })
    var randomNum = Math.floor(Math.random() * sfxArr.length )
    sound.play(sfxArr[randomNum], 1);
}

I have tried async, ive tried adding a isCooldown = false and setting it to true when it runs then false again, have tried a timeout, but with varying lengths this would be a little heavy handed.

0 Answers0