To add on to what Nexus said, here are some notes.
First of all, is all of that code happening inside of a game loop? I'm going to assume it is.
//creating the texture
sf::Texture keyTexture;
//loading the file
keyTexture.loadFromFile("keysprite.png");
//creating a vector with an array of 7 sprites
std::vector<sf::Sprite> keySprites(7, sf::Sprite(keyTexture));
//for loop to check through array and set sprite positions
Assuming this is happening in your game loop, you are reloading your file and recreating your sprites every frame. You should create them once before entering your game loop. This also applies to the keyMusic variable later on in your code.
//for loop to check through array and set sprite positions
for(int i = 0; i < keySprites.size(); i++)
{
keySprites[0].setPosition(460, 80);
keySprites[1].setPosition(140, 275);
keySprites[2].setPosition(800, 300);
keySprites[3].setPosition(700, 500);
keySprites[4].setPosition(125, 500);
keySprites[5].setPosition(250, 850);
keySprites[6].setPosition(700, 800);
}
Why are you setting the position of the sprites in a loop? This loop isn't needed since you are setting each individual sprite. Notice how you are looping with the variable "i", but then you never use "i" in the loop. You are setting all of your sprites to the same thing seven different times.
if(keySpriteVisible == false)
{
keySprites[6].setColor(sf::Color::Transparent);
}
Again, assuming all of this code is happening inside of a game loop, this won't really do anything. You are setting the color of keySprite[6], but then in your next loop you will just recreate keySprite[6] so it will lose its transparency (refer back to my first comment above). This is why your current solution does not work.
If you create the sprite vector before your game loop, then perhaps a better solution to your problem would be to remove that element from the vector when you detect a collision. Then, later when you loop through your objects to draw them, the key will be missing from the vector so it will not get drawn. This is what Nexus is referring to.