Object not beign destroyec correctly

hello everybody , 

it is a "Lucher " as father that lunches a missile as “newMis” ,then i pass the parameter father to the missile , and what i want is when the missile is destroyed, call a function of the father “DestroyedMissile()”

then, i pass a body obj “newMiss.father = father_” thorugh a collision event and then i access it from “event.target.father”

and then the father crash with other object and it is destroyed passing target as father in another collision listener the listener of the father

function Destroy(target) physics.removeBody( target ) target:removeSelf( ) target = nil end

the problem is that the newMis.father is not destroyed when i call this function Destroy(target) of the father body, when the father collidies in its collision listener

and then the missile is calling the “newMis.father:DestroyedMissile()” but the father suposse to be nil cause is destroyed because had a collision

and i supposed to have an error here cause the circle as father "was destroyed " so i dont now

and inside the DestroyedMissile() is lunched a new Missile 

and then a new missile is lunched from (0,0) and no idea of what father is passing in LunchMissile(self)

function circle:DestroyedMissile() timer.performWithDelay( 100, function() LunchMissile(self) end ) end 

my complete code Luncher.lua

local Luncher = {} local misiles local physics local player local Destroy local camera local SceneGroup local Collision function Collision(event) if(event.phase == "began" and event.other.myName ~= nil )then if(event.other.myName == "missile")then if(event.other.element == event.target.myName )then if(event.other.crashFather == true )then -- here i call to destroy the father when it crash timer.performWithDelay( 10,function() Destroy(event.target) end) end else event.target:removeEventListener( "collision", Collision ) --this way perform the functin when perform the timer BAD WAY --timer.performWithDelay( 5000, Destroy(event.target)) local destroy = function() Destroy(event.target) end timer.performWithDelay( 10,destroy) end end end end function Luncher:init(SceneGroup\_ , camera\_, \_physics, player\_) physics = \_physics player = player\_ camera = camera\_ SceneGroup = SceneGroup\_ misiles = require("game.enemy.missile") misiles:init(SceneGroup, camera , physics) end local function LunchMissile(parent) if(parent~= nil)then parent.MissilesOnAir = parent.MissilesOnAir + 1 misiles:new(parent.x,parent.y , parent, player.square) end end function Luncher:new( x , y ) local circle = display.newCircle( x, y, 20 ) circle.MissilesOnAir = 0 circle.myName = "Luncher" physics.addBody( circle,"dynamic" ) circle.gravityScale = 0 SceneGroup:insert( circle ) camera:add( circle , 2 , false ) circle.transform = "transform" circle:addEventListener( "collision", Collision ) function circle:DestroyedMissile() --////////////////////////////////////////////////////////////// --passing the father "circle" as self but it suppossed to be nil ? timer.performWithDelay( 100, function() LunchMissile(self) end ) end --Passing the father "circle" LunchMissile(circle) end --////////////////////////////////////////////////////////////// ---Destroying the father , the same father i pass to the Missile function Destroy(target) physics.removeBody( target ) target:removeSelf( ) target = nil end return Luncher

and my Missile Lua file

local missile = {} local Mis local PATH = "game/enemy/" local SceneGroup , camera local physics local myJoint local MAX\_FORCE = 1 local VEL = 70 local MAX\_ANGLE\_VEL = 100 local Collision local listener = function(newMis) .... end local function destroy(newMis) if(newMis~= nil)then Runtime:removeEventListener( "enterFrame", newMis.eventListener ) physics.removeBody( newMis ) --calling the fahter and telling the missile is destroyed --but the father was destroyed so i supose to have an error trying to acces it dont , causefather was destroyed ? --but the father still is not a nil value so the function is calle , why? cause the father was destroyer cause it crashed with an object newMis.father:DestroyedMissile() newMis:removeSelf( ) newMis.father = nil newMis = nil end end function Collision( event ) if ( event.phase == "began" and event.other.myName ~= nil ) then if(event.other.myName ~= "BoundArea" and event.other.myName ~= "gravityArea" and event.other.myName ~= event.target.father.myName or event.other.myName == event.target.father.myName and event.target.crashFather == true ) then print("Collisino with "..event.other.myName) event.target:removeEventListener( "collision", Collision) --when the missile crash is beign destroyed here timer.performWithDelay( 10, function() destroy(event.target) end ) end elseif(event.phase == "ended" and event.other.myName ~= nil) then if(event.other.myName == event.target.father.myName) then event.target.crashFather = true print("crashFather") end end end function missile:new(x , y , father\_ , target) local newMis = display.newImage( PATH.."missile.png" , x , y) newMis.myName = "missile" newMis.damage = -10 --passing the father here newMis.father = father\_ SceneGroup:insert( newMis ) camera:add(newMis, 2, false) newMis.crashFather = false physics.addBody( newMis, "dynamic", {isSensor = true} ) newMis.gravityScale = 0 myJoint = physics.newJoint( "touch" ,newMis, newMis.x, newMis.y) myJoint:setTarget( 100, 200 ) myJoint.dampingRatio = 10 myJoint.maxForce = MAX\_FORCE newMis.target = target local funct = function() listener(newMis) end newMis.eventListener = funct newMis.able = true newMis.lastX = 0 newMis.lastY = 0 Runtime:addEventListener( "enterFrame", funct) newMis:addEventListener( "collision", Collision) end function missile:init(SceneGroup\_, camera\_ , physics\_) SceneGroup = SceneGroup\_ camera = camera\_ physics = physics\_ end return missile