So, I'm pretty sure the reason this happens is that when Godot instantiates your scene it also needs to instantiate your AudioStreamPlayer
sfx, which throws this error, because at this point the stream property of
sfx is still
null. To offer a solution I think we would need more code/context of what exactly you're trying to do.
My guess is, that you should rethink your approach though. E.g. what about just adding an AudioStreamPlayer node to your scene? And then, when you instantiate that scene, you can change the Player's stream property in the editor.