Deleting objects

I have a question about deleting objects created by function.

When I use this code the scrollCoin function deletes coins properly (one by one) but onCoinCollision deletes them all.

So basically I want onCoinCollision to delete only one coin that touches rocket but it deletes them all.

I have tried placing coins in table and directly spawnCoin( 100, 100, 0) like this.

I’m new to corona and i don’t really understand that.

Thank you :slight_smile:

function scrollCoin(self, event)     if self.y \> 1000 then         display.remove(self)         Runtime:removeEventListener("enterFrame", self)         Runtime:removeEventListener( "collision", onCoinCollision )         coin = nil     else     self.y = self.y + 6     end end function onCoinCollision(self, event)     if ( event.phase == "began" ) then             if event.object1.name == "rocket" then             display.remove ( self )             Runtime:removeEventListener("enterFrame", self)             Runtime:removeEventListener( "collision", onCoinCollision )             coin = nil             score = score + 1             print (score)         end     end end function spawnCoin(x, y, addSpeed)   local coin = display.newImage("coin\_kitty.png")   physics.addBody(coin, "dynamic")   coin.x = x   coin.y = y   coin.enterFrame = scrollCoin   Runtime:addEventListener( "enterFrame", coin )   coin.collision = onCoinCollision   Runtime:addEventListener( "collision", coin )   return coin end

Nobody had problems like that with coins created in function?

Edit: After 2 days of just trying I have managed to figure it out.

Nobody had problems like that with coins created in function?

Edit: After 2 days of just trying I have managed to figure it out.