You've overcomplicated things by making the haystack a container at all. It doesn't need to be and, in this situation, I would suggest it shouldn't. Remember, just because something is inside something else IN THE GAME WORLD, doesn't mean it has to actually be inside it. How I would do it is this:
Don't make the haystack a container. Put a flag on it, "hasneedle" (set this flag in the start script at the beginning of the game). The needle should be in the room, invisible.
Your "x haystack" and "search haystack" script will be this:
if (GetBoolean(haystack, "hasneedle")) {
if (ListContains(ScopeVisible(), needle)) {
msg ("There's a needle in the haystack.")
}
else {
msg ("Looking through the hay, you found a needle!")
MakeObjectVisible (needle)
}
}
else {
msg ("There's nothing else of interest in the haystack.")
}
Your "take needle" script will be this:
msg ("You take it.")
SetObjectFlagOff (haystack, "hasneedle")
AddToInventory (needle)
That should cover everything you want to do. Let me know if it doesn't.