Can't replicate object duplication in Multiplayer

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Rubin

Hello! I’m developing a multiplayer game about burgers where I have ingredients and a tray (which I can put the ingredient in). I have a mechanic that when I put the ingredient inside the tray the ingredient gets deleted from the main scene, duplicated, and added into the tray. But the weird thing is:

This process works fine when everyone is on the server, BUT if I put an ingredient into the tray and then a new player joins the server, it’ll give him an error and the ingredient will not be there for him.

What is even more weird is:

If I just delete the ingredient (and not duplicate it into the tray) it’ll work fine.
If I just duplicate the ingredient without deleting the original one, it’ll work fine.
If I do both, it’ll give error.

Main scene hierarchy
Tray hierarchy (“Ingredients” is where the ingredients are stored)
Error

# Simplified version of the Tray code

func _on_Area_body_entered(body):
    var clone = body.duplicate()
    $Ingredients.add_child(clone, true)
    body.queue_free()

In the code above, if comment add_child() or queue_free() line, it works, but with both at the same time, it doesn’t somehow.