When you press P to exit the pause, these 2 lines are executed:
if (event.type == Event::KeyPressed)
wait=false;
Then you enter in this if:
if(!wait)
And you immediately enter this if again (because P is still pressed at this moment):
if( Keyboard::isKeyPressed(Keyboard::P))
{
wait = true;
}
So the game is paused again.
Instead of doing this, you could handle the pause with only the following two lines:
if (event.type == Event::KeyPressed && event.key.code == sf::Keyboard::P)
wait = !wait;
Each time the P key is pressed, the game pauses or unpauses.
It sets wait to true if it's false (pause the game) and to false if it's true (unpause the game).