Attempt to index field 'contact' (a nil value)

hello,

I am getting This error

 Error:- attempt to index field ‘contact’ (a nil value)

 When I am using pre collision listener in my game. This function is called multiple times in my game.

Code :-

local function preCollision( event)

   event.contact.isEnabled = false

end

local function postCollision( event )

        Runtime:removeEventListener( “preCollision” )

        Runtime:removeEventListener( “postCollision” )

  end

I am also removing listener every times when postCollision is called

This error occurred Some times.

Please help me out from this black hole…?

I am experiencing the same problem. Any idea how to overcome this?

I got the solution for it, Check for nil value

 local function preCollision( event)

        if(event.contact==nil) then

            print(“nil”)

        else

            event.contact.isEnabled = false

        end

        

    end

I am experiencing the same problem. Any idea how to overcome this?

I got the solution for it, Check for nil value

 local function preCollision( event)

        if(event.contact==nil) then

            print(“nil”)

        else

            event.contact.isEnabled = false

        end

        

    end