Audio PlayOneShot Help

Im trying to create a sprinting script. I have everything working stamina, sprinting speed, but my audio is not working. Im trying to make that when your stamina is less than (amount)
it plays the sound once. Im not going to post the whole script but here is the part im stuck in :

if(stamina <= 30 && !audio.isPlaying)
   {
   audio.PlayOneShot(exhaustion);
   }

In this code some problem. For example , if player’s stamina = 30 , audio will play. whenever stamina = 29,28 ,27 …etc ,in each condition audio will play. To avoid this , use a boolean like

   public bool hasPlayedAudio = false;

   if(stamina <= 30   && !hasPlayedAudio)
   {
    hasPlayedAudio = true;
     audio.PlayOneShot(exhaustion);
   }

If once audio play, hasPlayedAudio become true and audio will not play again.