Problem accessing child GameObjects

Hello, I need to change the value of a variabile from another script.
Here is the code I’m using:

playerPrefab.GetComponentsInChildren(true)[0].allWeapons[0]=(WeaponScript)transform.Find("BallisticKnife");

In other words I need to change the allWeapon[0] value with a gameobject (child of PlayerPrefab) called “BallisticKnife”. The type of BallisticKnife is “WeaponScript”. The problem is that unity report an error:

error CS0030: Cannot convert type
UnityEngine.Transform' to WeaponScript’

Any help please ? Many thanks !

If i understand your question correctly you need to not use get component once you find the object.

transform.Find("BallisticKnife").GetComponent<WeaponScript>();

Transform.Find returns a transform. You don’t cast a Transform to the type of your script. Get the Component you need attached to the transform.

GetComponentsInChildren(true) doesn’t mean anything. Your code doesn’t convey meaning. You should try rewriting it again to do so. We can help.