Help request: Basic logic does not appear to work in this one instance. Obviously I've messed up

Hi I'm a relative noob to game dev. I've messed around with unity, gamemaker and godot in the past, but never to a serious degree. This is my first time using Lua. I've been following SquidGods tutorial and am messing around building on the shmup he showed there. I'm trying to turn it into a sort of musical shmup with notes played every time you shoot and more shots (and notes) being unlocked through pickups. So, each time you gain a pickup a new note (or notes) start being played and there is a consumate increase in shots fired.

It starts out fine, only the innitial note/shot triggers in rythm. Where I'm getting stuck is that despite the logic suggesting only one new note should be unlocked on the pickup, they are all being triggered, still at the right times, as though the number of pickups is higher. I have the number of pickups collected printed on screen so I can see it's not adding multiples somehow, and only one pickup gets spawned in the game so the pickupScore is only 0 or 1.

Here's the relevant code segment:

function createBulletTimerStart()
beatOneTimer = pd.timer.performAfterDelay(minim, function ()
shootBeat(pnoEflat, beatOneTimer, 0, 0)
beatTwoTimer = pd.timer.performAfterDelay(bar, function ()
shootBeat(pnoGflat, beatTwoTimer, 1, -1)
beatThreeTimer = pd.timer.performAfterDelay(bar + minim, function ()
shootBeat(pnoCflat, beatThreeTimer, 2, 1)

beatFourTimer = pd.timer.performAfterDelay(bar*2 + minim, function ()
    shootBeat(pnoEflat, beatFourTimer, 0, 0)
beatFiveTimer = pd.timer.performAfterDelay(bar*3, function ()
    shootBeat(pnoGflat, beatFiveTimer, 1, -1)
beatSixTimer = pd.timer.performAfterDelay(bar*3 + minim, function ()
    shootBeat(pnoCflat, beatSixTimer, 2, 1)


function shootBeat(note, timer, pickup, vSpeed)
if pickupScore >= pickup then

timer = pd.timer.performAfterDelay(phrase, function ()
    shootBeat(note, phrase, pickupScore, vSpeed)


As I hope should be clear, the first and fourth notes play at the beginning and after the first pickup the second and fifth should also play. However, depite pickupScore being only 1 at that point, the third and sixth also play.

What might I have missed? Do I need to give more info?

Can anyone think of any reason this might be happening?

Put your timer = ...performAfterDelay call inside your if pickupScore... clause inside shootBeat.