Remove Self

Hey guys I have my code set up so when you touch the object it will “remove self” but when their is two on the screen and you touch one of the objects it removes a object by it.

local numberSmiles = 15 --local variable; local function spawnSmiles() for i=1,numberSmiles do smile = display.newImageRect("rocket.png", 45, 45); -- smile:setReferencePoint(display.CenterReferencePoint); --not necessary; center is default smile.x = math.random(-10, 400); smile.y = math.random(55,250) transition.to( smile, { time=math.random(2000,8000), x=earth.x , y=earth.y, } ); end local function rocketdestroyed( event ) if (event.phase == "began") then score.add(event.target.value) smile:removeSelf() end end smile:addEventListener("touch",rocketdestroyed) end timer.performWithDelay( 1000, spawnSmiles, 0 ) --fire every 10 seconds

Try using 

smile[i] = display.newImageRect("rocket.png", 45, 45);

And assign event listeners to each entry of the array. 

Try using 

smile[i] = display.newImageRect("rocket.png", 45, 45);

And assign event listeners to each entry of the array.