I heard that before hashem created this world he created many other worlds before and then he destroyed them. The others ones didn’t please him, but this one did please him. My question is: Why did Hashem have to do that if Hashem knows the future, then he knows everything, so why did he have to create and then destroy the other worlds? Is that a Shailah?
The Midrash states, as you note, that Hashem created worlds and destroyed them before this world was created (see in particular Pirkei de-Rabbi Eliezer, Chap. 3).
Of course, the question, as you note, is what is the point of creating worlds only to have them destroyed?
This is a very deep issue, which is dealt with primarily in the Kabbalistic literature. The general idea that is given is that the worlds that were created and destroyed provide the required backdrop to give our own world its balance of potential for evil on the one hand, and potential for mending the evil on the other.
Our own world is therefore based on the worlds that existed but were destroyed, bringing the full power of “judgment” into our world, yet allowing it the capacity to reach a destiny of eternal life.
I realize these concepts are deep, and going further is beyond the scope of the site. I nevertheless hope this helps a little.