Open the behavior screen of the chest object and add this:
The proximity block checks if the player is close and the keyboard block checks if spacebar is pressed down. The AND block is there because the player should be close in order to open the chest, and the player should press space bar too.
@Latif thanks,i got another how could i make it emit an object.
do i just connect the keyboard input and emit.
@USERNAME55 when i do it like that you,could press space far away and get the apple.
do this instead