ah! All thanks to the cell membrane!
The cell membrane contains phospholipids that are amphiphilic (polar - water attracting and non-polar - water repelling) in nature. That's why the cell membrane allows non-polar materials to pass through but not polar materials. (if you're learning junior science you really don't need to know this!) The polar materials require proteins found on the cell membrane called protein channels or carrier proteins to pass through. (their names are pretty self-explanatory!)
All the best!