Problem with player collecting items in-game.

I want the player to be able to pick this key up and keep moving.The reason for this is the player is supposed to roll into the key and then into the lock in one swift move. Instead the player bounces off the key even though it removes itself. 

function grabKey(event)

if event.phase == “began” then

if(event.object1.name == “keyBlue” and event.object2.name == “myPlayer”) then

print(“Player has grabbed the key!”)

playerHasKey = true

event.object1:removeSelf()

end

end

end

This is attached to a collision event listener. How would I go about fixing this? I tried post-collision but literally nothing happened (didn’t even print the text). I was thinking to somehow set it up in a way that if the player gets within 5 pixels it removes itself? Can’t figure out how to do so for the life of me.

Any help would be appreciated.

Problem has been solved.

In the physics.addBody area I added:  isSensor = true  which made it do exactly what I wanted.

Problem has been solved.

In the physics.addBody area I added:  isSensor = true  which made it do exactly what I wanted.