Attempt to index local 'contact' a nil value

Currently, I am working on pre-collision for one-way platforms. I am pleased with the result but occasionally I get this error:

ERROR: Runtime error characterfunctions.lua:216: attempt to index local 'contact' (a nil value) stack traceback: characterfunctions.lua:216: in function '?' ?: in function \<?:190\>

I am not sure what’s causing it, and how to isolate it, but here’s the code:

 local contact = event.contact -- Line 212 local other = event.other if( other.isFloating ) then if( contact.isEnabled and self.y \> other.y - other.height / 2) then contact.isEnabled = false end end -- Line 219

The error is the first line in the first if statement of this code. 

Any help would be greatly appreciated, thanks!

Easy fix would be to not process if no contact.

 local contact = event.contact local other = event.other if( contact and other and other.isFloating ) then if( contact.isEnabled and self.y \> other.y - other.height / 2) then contact.isEnabled = false end end 

Note: This sound a lot to me like you’re processing an object that just got deleted or was not correctly destroyed, but that is just a guess.

Neither of the processed objects are going to be destroyed at any time of the level unless the player dies, but I have not written the character’s death code yet.

Also, thanks! It worked.

Easy fix would be to not process if no contact.

 local contact = event.contact local other = event.other if( contact and other and other.isFloating ) then if( contact.isEnabled and self.y \> other.y - other.height / 2) then contact.isEnabled = false end end 

Note: This sound a lot to me like you’re processing an object that just got deleted or was not correctly destroyed, but that is just a guess.

Neither of the processed objects are going to be destroyed at any time of the level unless the player dies, but I have not written the character’s death code yet.

Also, thanks! It worked.