Remove Object on Collision

I been breaking my head trying to remove objects when it collides with a floor
I keep getting (nil value) errors. I tried multiple solutions none seem to work
basically I have an object that keeps re spawning from a function. So a single
image will keep spawning every 1 second in different location and once the
image hits the floor I want that image to be removed. I can do this easily if it
was a single image but since its an image from a spawn function it gives me
a (nil value) error if i use the imageName:removeSelf()

Any help is greatly appreciated Thanks! [import]uid: 30314 topic_id: 16148 reply_id: 316148[/import]

I haven’t tried it myself, but have you tried the fruit samurai tutorial? There is a “floor” created on the bottom to remove fruit when it touches it. I am fairly new but I think that should give you a good start. [import]uid: 85045 topic_id: 16148 reply_id: 60099[/import]

You might need to keep spawned objects in a table so you can keep track of them

Raúl Beltrán
MIU Games [import]uid: 44101 topic_id: 16148 reply_id: 60100[/import]

Check to see if the object is nil before removing it.
try something like this

if event.phase == "ended" and event.object1 then event.object1.bodyType = "static" event.object1:removeSelf() end [import]uid: 38820 topic_id: 16148 reply_id: 60112[/import]

Thanks for all the help I manage to solve my issue by using the same
method as Samurai Fruit Sample Code.

Thanks @ idkokos! [import]uid: 30314 topic_id: 16148 reply_id: 60208[/import]