Welcome to the forums @AI_level_4!
Is the node you are adding the children to in the scene? It’s been awhile since I’ve looked into node reparenting but I believe this can sometimes cause issues.
The error message seems to be saying that the node the script it attached to, the one you are adding the node(s) to, does not have a viewport. This is probably because either the node is a Node2D/Control and so when it tries to update after being added/removed, it calls a function that needs a viewport.
Though from my Google searches, it seems the code you are using should work.
Maybe try caching the list of nodes and perform the reparenting in process or physics_process? Maybe something with the timing of the collision callback is causing the issue.
Something else to potentially try, if you cannot get reparenting working, is using the duplicate function instead. Then you can do something like this:
for node in node_list:
# make a copy
var clone = node.duplicate()
# no longer need the original, so delete it
node.queue_free()
# add the duplicate
add_child(clone)
I’m not sure if it would work, but sometimes duplicating works. I doubt it’s an optimal solution due to more memory/processing costs in the short term, but if you are only duplicating a few dozen nodes at a time it shouldn’t cause issues on even constrained platforms, at least I do not think it would.