There are two levels to this. First handling the issue within a single 'run' of the game and second handling it over multiple 'runs'.
Within a single run you need to:
- Make a variable, a global variable would be easiest, such as global.key_collected.
- Set the variable to false at the start of the game
- only spawn the key if the variable is false
- once you collect the key, change the variable to true
If you want it to persist through multiple runs of the game (which presumably you will):
- Make a variable, a global variable would be easiest, such as global.key_collected.
- After making the variable, load it in, with a default of false
- Set the variable to false at the start of the game
- only spawn the key if the variable is false
- once you collect the key, change the variable to true
- save the variable state upon game exit, or change, or whenever you want
To understand more about saving and loading, look up some tutorials on YouTube. I would suggest starting with Shaun Spalding's ini tutorial as it is probably the easiest and will work for what you're doing.