Making a object a child of another

I have had a look at other questions but none of them helped me…

I have a player and I have a simple inventory and when you click on a weapon to equip, it creates the weapon where it should be, but the object would become a child of the player hand. I have tried “childObject.transform.parent = parentObject.transform” it wouldn’t work

Every time the object gets created a warning pops up saying: “Setting a parent of a transform which resides in a prefab is disabled to prevent data corruption” I have tried it with both my player and my weapon not being a prefab and it still wouldn’t work

How can this be fixed? (Im using JavaScript)

transform.weapon.parent = transform.hand;

i think this is what your looking for