problem with incrementing values per off screen objects

Hey guys, to keep things sweet and simple, what Im trying to do is make a value called “Obstacles” and to increase it by 1 per each object that scrolls off screen on X axis. 

The problem that happens is that either 1 object increments 1 every second its off screen which results in a huge number for just 1 obstacle dodged. is it that it is still scrolling even off screen? if so how can I remove the block individually or just increment by 1 only? 

thanks 

Here is how its set up:

local obstacles = 0 local yPos = {50,110,200} function updateNum( event ) obstacles = obstacles + 1 end unction createBlock(event) local rnd = math.floor(math.random() \* 4) + 1 b = display.newImage('images/block3.png', display.contentWidth, yPos[math.floor(math.random() \* 3)+1]) b.name = 'block' physics.addBody(b, "static") blocks:insert(b) end function gameLoop( event ) if(blocks ~= nil)then for i = 1, blocks.numChildren do blocks[i].x = blocks[i].x - speed if(blocks[i].x \< -0) then print("+1!!") obstacles = obstacles +1 end end end end Runtime:addEventListener("enterFrame", gameLoop) timerSrc = timer.performWithDelay(1000, createBlock, 0)

[lua]

function gameLoop( event )

  if(blocks ~= nil)then

    for i = blocks.numChildren, 1, -1 do

      blocks[i].x = blocks[i].x - speed

        if(blocks[i].x < -0) then

          print("+1!!")

          display.remove(blocks[i])

          blocks[i] = nil

          obstacles = obstacles +1

        end

    end

  end

end

[/lua]

[/

Hi @nick_sherman, thanks for the post. Firstly I deleted my other reply because I failed to add a key part from your code above. After pasting the entire code above, it works as it should, thanks for that. 

There is a small problem that I have and its that in the top corner of my screen (probably at -0 coords), I now have a random image of my  block sitting in the corner which flickers. how can I remove that? 

thanks for the help

[lua]

function gameLoop( event )

  if(blocks ~= nil)then

    for i = blocks.numChildren, 1, -1 do

      blocks[i].x = blocks[i].x - speed

        if(blocks[i].x < -0) then

          print("+1!!")

          display.remove(blocks[i])

          blocks[i] = nil

          obstacles = obstacles +1

        end

    end

  end

end

[/lua]

[/

Hi @nick_sherman, thanks for the post. Firstly I deleted my other reply because I failed to add a key part from your code above. After pasting the entire code above, it works as it should, thanks for that. 

There is a small problem that I have and its that in the top corner of my screen (probably at -0 coords), I now have a random image of my  block sitting in the corner which flickers. how can I remove that? 

thanks for the help