Problem with removing objects after collision

Hi. 

I’m trying to make my first game. I want “things1” to disappear after collision with “KittyKat”, but I have no idea how to do that. I don’t know what part of my code will you need, so I’m posting everything. I’m sorry for my English. It’s bad because I’m from Poland.

pls help :frowning:

local physics = require ( "physics" ) physics.start() physics.setGravity( 0, 0 ) -- Seed the random number generator math.randomseed( os.time() ) -- Configure image sheet local sheetOptions = { &nbsp;&nbsp; &nbsp;frames = &nbsp;&nbsp; &nbsp;{ &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp; &nbsp;-- 1) ZosiaSosia &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;x = 0, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;y = 0, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;width = 119, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;height = 130 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp; &nbsp;-- 2) Fiona &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;x = 0, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;y = 130, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;width = 111, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;height = 120 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp; &nbsp;-- 3) Goblin &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;x = 0, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;y = 251, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;width = 111, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;height = 120 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp; &nbsp;-- 4) szczur &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;x = 0, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;y = 373, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;width = 70, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;height = 61 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp; &nbsp;-- 5) miska &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;x = 0, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;y = 436, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;width = 60, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;height = 35 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}, &nbsp;&nbsp; &nbsp;} } local objectSheet = graphics.newImageSheet( "Things0.png", sheetOptions ) -- Initialize variables local lives = 3 local score = 0 local died = false local thingsTable = {} local KittyKat local gameLoopTimer local livesText local scoreText -- Set up display groups local backGroup = display.newGroup() -- Display group for the background image local mainGroup = display.newGroup() -- Display group for the things local uiGroup = display.newGroup() -- Display group UI objects like the score -- Load the background local background = display.newImageRect( backGroup, "background.PNG", 800, 1400 ) background.x = display.contentCenterX background.y = display.contentCenterY -- Load the KittyKat KittyKat = display.newImageRect( mainGroup, "KittyKat.png" , 119, 130 ) KittyKat.x = display.contentCenterX KittyKat.y = display.contentHeight - 100 physics.addBody( KittyKat, { radius=30, isSensor=true } ) KittyKat.myName = "KittyKat" -- Display lives and score livesText = display.newText( uiGroup, "Lives: " .. lives, 200, 80, native.systemFont, 36 ) scoreText = display.newText( uiGroup, "Score: " .. score, 400, 80, native.systemFont, 36 ) -- Hide the status bar display.setStatusBar( display.HiddenStatusBar ) local function updateText() &nbsp;&nbsp; &nbsp;livesText.text = "Lives: " .. lives &nbsp;&nbsp; &nbsp;scoreText.text = "Score: " .. score end -- Load the things local function createThings() -- insert ZosieSosie &nbsp;&nbsp; &nbsp;local newThings = display.newImageRect( mainGroup, objectSheet, 1, 119, 130 ) &nbsp;&nbsp; &nbsp;table.insert( thingsTable, newThings ) &nbsp;&nbsp; &nbsp;physics.addBody( newThings, "dynamic", { radius=40, bounce=0.8 } ) &nbsp;&nbsp; &nbsp;newThings.myName = "things1" &nbsp;&nbsp; &nbsp;local whereFrom = math.random( 3 ) &nbsp;&nbsp; &nbsp;if ( whereFrom == 1 ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- From the left &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.x = -60 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.y = math.random( 5000 ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings:setLinearVelocity( math.random( 40,120 ), math.random( 20,60 ) ) &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;elseif ( whereFrom == 2 ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- From the top &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.x = math.random( 5000 ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.y = -60 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings:setLinearVelocity( math.random( -40,40 ), math.random( 40,120 ) ) &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;elseif ( whereFrom == 3 ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- From the right &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.x = display.contentWidth + 60 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.y = math.random( 5000 ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings:setLinearVelocity( math.random( -120,-40 ), math.random( 20,60 ) ) &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;-- insert Fiona &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;local newThings = display.newImageRect( mainGroup, objectSheet, 2, 111, 120 ) &nbsp;&nbsp; &nbsp;table.insert( thingsTable, newThings ) &nbsp;&nbsp; &nbsp;physics.addBody( newThings, "dynamic", { radius=40, bounce=0.8 } ) &nbsp;&nbsp; &nbsp;newThings.myName = "things2" &nbsp;&nbsp; &nbsp;local whereFrom = math.random( 3 ) &nbsp;&nbsp; &nbsp;if ( whereFrom == 1 ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- From the left &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.x = -60 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.y = math.random( 3000 ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings:setLinearVelocity( math.random( 40,120 ), math.random( 20,60 ) ) &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;elseif ( whereFrom == 2 ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- From the top &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.x = math.random( 4000 ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.y = -60 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings:setLinearVelocity( math.random( -40,40 ), math.random( 40,120 ) ) &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;elseif ( whereFrom == 3 ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- From the right &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.x = display.contentWidth + 60 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.y = math.random( 3000 ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings:setLinearVelocity( math.random( -120,-40 ), math.random( 20,60 ) ) &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;--insert Goblin &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;local newThings = display.newImageRect( mainGroup, objectSheet, 3, 111, 120 ) &nbsp;&nbsp; &nbsp;table.insert( thingsTable, newThings ) &nbsp;&nbsp; &nbsp;physics.addBody( newThings, "dynamic", { radius=40, bounce=0.8 } ) &nbsp;&nbsp; &nbsp;newThings.myName = "things2" &nbsp;&nbsp; &nbsp;local whereFrom = math.random( 3 ) &nbsp;&nbsp; &nbsp;if ( whereFrom == 1 ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- From the left &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.x = -60 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.y = math.random( 3000 ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings:setLinearVelocity( math.random( 40,120 ), math.random( 20,60 ) ) &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;elseif ( whereFrom == 2 ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- From the top &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.x = math.random( 3000 ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.y = -60 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings:setLinearVelocity( math.random( -40,40 ), math.random( 40,120 ) ) &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;elseif ( whereFrom == 3 ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- From the right &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.x = display.contentWidth + 60 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.y = math.random( 3000 ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings:setLinearVelocity( math.random( -120,-40 ), math.random( 20,60 ) ) &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;--insert szczur &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;local newThings = display.newImageRect( mainGroup, objectSheet, 4, 70, 61 ) &nbsp;&nbsp; &nbsp;table.insert( thingsTable, newThings ) &nbsp;&nbsp; &nbsp;physics.addBody( newThings, "dynamic", { radius=40, bounce=0.8 } ) &nbsp;&nbsp; &nbsp;newThings.myName = "things1" &nbsp;&nbsp; &nbsp;local whereFrom = math.random( 3 ) &nbsp;&nbsp; &nbsp;if ( whereFrom == 1 ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- From the left &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.x = -60 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.y = math.random( 3000 ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings:setLinearVelocity( math.random( 40,120 ), math.random( 20,60 ) ) &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;elseif ( whereFrom == 2 ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- From the top &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.x = math.random( 3000 ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.y = -60 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings:setLinearVelocity( math.random( -40,40 ), math.random( 40,120 ) ) &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;elseif ( whereFrom == 3 ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- From the right &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.x = display.contentWidth + 60 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.y = math.random( 3000 ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings:setLinearVelocity( math.random( -120,-40 ), math.random( 20,60 ) ) &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;--insert miska &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;local newThings = display.newImageRect( mainGroup, objectSheet, 5, 60, 35 ) &nbsp;&nbsp; &nbsp;table.insert( thingsTable, newThings ) &nbsp;&nbsp; &nbsp;physics.addBody( newThings, "dynamic", { radius=40, bounce=0.8 } ) &nbsp;&nbsp; &nbsp;newThings.myName = "things1" &nbsp;&nbsp; &nbsp;local whereFrom = math.random( 3 ) &nbsp;&nbsp; &nbsp;if ( whereFrom == 1 ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- From the left &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.x = -60 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.y = math.random( 3000 ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings:setLinearVelocity( math.random( 40,120 ), math.random( 20,60 ) ) &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;elseif ( whereFrom == 2 ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- From the top &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.x = math.random( 3000 ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.y = -60 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings:setLinearVelocity( math.random( -40,40 ), math.random( 40,120 ) ) &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;elseif ( whereFrom == 3 ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- From the right &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.x = display.contentWidth + 60 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings.y = math.random( 3000 ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newThings:setLinearVelocity( math.random( -120,-40 ), math.random( 20,60 ) ) &nbsp;&nbsp; &nbsp;end end -- Moving KittyKat local function dragKittyKat( event ) &nbsp;&nbsp; &nbsp;local KittyKat = event.target &nbsp;&nbsp; &nbsp;local phase = event.phase &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;if ( "began" == phase ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- Set touch focus on the KittyKat &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;display.currentStage:setFocus( KittyKat ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- Store initial offset position &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;KittyKat.touchOffsetX = event.x - KittyKat.x &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;KittyKat.touchOffsetY = event.y - KittyKat.y &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;elseif ( "moved" == phase ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- Move the KittyKat to the new touch position &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;KittyKat.x = event.x - KittyKat.touchOffsetX &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;KittyKat.y = event.y - KittyKat.touchOffsetY &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; elseif ( "ended" == phase or "cancelled" == phase ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Release touch focus on the KittyKat &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; display.currentStage:setFocus( nil ) &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;return true -- Prevents touch propagation to underlying objects end KittyKat:addEventListener( "touch", dragKittyKat ) local function gameLoop() &nbsp;&nbsp; &nbsp;--Create new things &nbsp;&nbsp; &nbsp;createThings() &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;--Remove things which have drifted &nbsp;&nbsp; &nbsp;for i = #thingsTable, 1, -1 do &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local thisThings = thingsTable[i] &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if ( thisThings.x \< -100 or &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; thisThings.x \> display.contentWidth + 100 or &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; thisThings.y \< -100 or &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; thisThings.y \> display. contentHeight + 100 ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;display.remove( thisThings ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;table.remove( thingsTable, i ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;end end gameLoopTimer = timer.performWithDelay( 2000, gameLoop, 0 ) &nbsp;&nbsp; &nbsp; local function restoreKittyKat() &nbsp;&nbsp; &nbsp;KittyKat.isBodyActive = false &nbsp;&nbsp; &nbsp;KittyKat:setLinearVelocity( 0, 0 ) &nbsp;&nbsp; &nbsp;KittyKat.x = display.contentCenterX &nbsp;&nbsp; &nbsp;KittyKat.y = display.contentHeight - 100 &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;-- Fade in the KittyKat &nbsp;&nbsp; &nbsp;transition.to( KittyKat, {alpha=1, time=4000, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;onComplete = function() &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;KittyKat.isBodyActive = true &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;died = false &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;} ) end local function onCollision( event ) &nbsp;&nbsp; &nbsp;if ( event.phase == "began" ) then &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local obj1 = event.object1 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local obj2 = event.object2 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if ( ( obj1.myName == "KittyKat" and obj2.myName == "things2" ) or &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; ( obj1.myName == "things2" and obj2.myName == "KittyKat" ) ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if ( died == false ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; died = true &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- Update lives &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;lives = lives - 1 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;livesText.text = "Lives: " .. lives &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if ( lives == 0 ) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;display.remove( KittyKat ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;KittyKat.alpha = 0 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;timer.performWithDelay( 500, restoreKittyKat ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;if ( event.phase == "began" ) then &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local obj1 = event.object1 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local obj2 = event.object2 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if ( ( obj1.myName == "KittyKat" and obj2.myName == "things1" ) or &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; ( obj1.myName == "things1" and obj2.myName == "KittyKat" ) ) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- Increase score &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;score = score + 100 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;scoreText.text = "Score: " .. score &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;end&nbsp;&nbsp; &nbsp; end Runtime:addEventListener( "collision", onCollision )

Hello,

This is a common mistake. You can’t remove a physics body while a collision is happening. Just delay the removal for a single frame…

Replace.

display.remove( KittyKat )

with

timer.performWithDelay( 1, function () display.remove( KittyKat ) end )

That should help, but I didn’t check the whole thing…

Thank you for your answer, but nothing has changed.

It needs to be a longer time. More like 10ms. 

I’m sorry, but I don’t know what do you mean. How I can change that? This is my first game, I never did somethig like that, and I’m learning in a language I don’t speak. I need more specific instructions.

Hello,

This is a common mistake. You can’t remove a physics body while a collision is happening. Just delay the removal for a single frame…

Replace.

display.remove( KittyKat )

with

timer.performWithDelay( 1, function () display.remove( KittyKat ) end )

That should help, but I didn’t check the whole thing…

Thank you for your answer, but nothing has changed.

It needs to be a longer time. More like 10ms. 

I’m sorry, but I don’t know what do you mean. How I can change that? This is my first game, I never did somethig like that, and I’m learning in a language I don’t speak. I need more specific instructions.