almost everything stop after a collision

Hi guys, I made a collision using the following code:

function onCollision( event )  
 if ( event.phase == "began" ) then  
 if event.object1.myName == "lines" and event.object2.myName == "player" then  
   
 event.object1.alpha = 0.001  
 scrolling = true  
 lines[i].parent:remove(lines[i])  
 lines[i] = nil  
 score = score + 100  
  
  
 media.playSound( "suoni/boing1.wav" )  
  
  
 local function animate()  
 bg1:translate(0, 3)  
 bg2:translate(0, 3)  
 bg3:translate(0, 3)  
 bg4:translate(0, 3)  
 bg5:translate(0, 3)  
 bg6:translate(0, 3)  
 bg7:translate(0, 3)  
 bg8:translate(0, 3)  
 bg9:translate(0, 3)  
 bg10:translate(0, 3)  
 bg11:translate(0, 3)  
 bg12:translate(0, 3)  
 bg13:translate(0, 3)  
 bg14:translate(0, 3)  
 bg15:translate(0, 3)  
 bg16:translate(0, 3)  
 bg17:translate(0, 3)  
 bg18:translate(0, 3)  
 bg19:translate(0, 3)  
 bg20:translate(0, 3)  
 bg21:translate(0, 3)  
 end  
  
 Runtime:addEventListener( "enterFrame", animate );  
  
 local function remove()  
 Runtime:removeEventListener("enterFrame", animate)  
 end  
  
 trmRemove = timer.performWithDelay(500, remove, 0)  
  
 local function animateSpeedCoin()  
 coin:translate(0, 3)  
 end  
  
 Runtime:addEventListener( "enterFrame", animateSpeedCoin );  
  
 local function removeSpeedCoin()  
 Runtime:removeEventListener("enterFrame", animateSpeedCoin)  
 end  
  
 trmRemove = timer.performWithDelay(500, removeSpeedCoin, 0)  
  
  
 end  
   
 elseif ( event.phase == "ended" ) then  
   
 if event.object1.myName == "coin" and event.object2.myName == "player" then  
 event.object1:removeSelf()  
  
 end  
 end  
 end   
  
  
 Runtime:addEventListener( "collision", onCollision )  

the problem is that when “player” collide with “coin”, “coin” disappear (like it’s supposed to be), but every function stop, when they won’t.

Do you know why?

Thanks :slight_smile: [import]uid: 122056 topic_id: 34259 reply_id: 334259[/import]

First, you’re referencing lines[i] but we have no idea what “i” is.

Secondly, your function is only going to fire if there is a collision between player and a line object and the animation’s stop a half second later.

Since you’re removing lines[i] you will no longer be in contact with it.
[import]uid: 199310 topic_id: 34259 reply_id: 136237[/import]

First, you’re referencing lines[i] but we have no idea what “i” is.

Secondly, your function is only going to fire if there is a collision between player and a line object and the animation’s stop a half second later.

Since you’re removing lines[i] you will no longer be in contact with it.
[import]uid: 199310 topic_id: 34259 reply_id: 136237[/import]