Cannot instantiate objects with a parent which is persistent. New object will be created without a parent

I am creating a first person shooter. I want to initiate a prefab(scope) onto another initiated prefab(gun).First i used this code.

if(Input.GetKeyDown(KeyCode.M))
{
AddScope(s);

    }

public void AddScope(Scope newscope)
{
Debug.Log(“AddScope”);
if(scope != null && scopepoint.childCount >0)
{
RemoveScope();
Destroy(scopepoint.transform.GetChild(0).gameObject);
}
Debug.LogWarning(“In Scope method”+scope.Length);
if (scope[0] == null)
{
scopeobject = Instantiate(newscope.gameObject, scopepoint.transform);
Debug.Log(“Equip”);
}

        scopeobject.transform.localPosition = Vector3.zero;
        scopeobject.transform.localRotation = Quaternion.identity;
   
    scope[0] = newscope;
    Debug.Log(scope[0]);
}

and the scope object is initaiting under a scope object which is a part of gun prefab.
Now i want to try same but with a UI button
public void AAAAAAAAAAA()
{
scope = new Scope[1];
AddScope(s);

}

but when i try this it gives “Cannot instantiate objects with a parent which is persistent. New object will be created without a parent.” this error.
And also I use an array in start method i gave the array size 1, but when I click the button the array size goes to zero thats the reason i am initating the scope array size as 1 in the method that is used for UI button.