Particle System enable when carrying

I am trying to get the particle system to only emit or enable when player is carrying. However when I try to add to my script to enable, it states I cannot not just make a module. I tried using this scripting API, but I come up with the same error.
What I am having problems with and where I am trying to make it work.

In the code below, I am trying to enable the particles on Pickup() and then disable them on Drop(). Also must point out that the player must be close for this to work and assign the particles and gameobject for the player to pickup.
Is there a problem with the API or am I not plugging in my code right?
Code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class GrabCarryObject : MonoBehaviour
{
    public GameObject item;
    public GameObject tempParent;
    public Transform guide;
    public float range;
    public bool carrying;
    AnimalAI animalAI;

    private void OnTriggerEnter(Collider other)
    {
        if(other.gameObject.CompareTag("Pickups"))
        {
            item = GameObject.FindGameObjectWithTag("Pickups");
            item.GetComponent<Rigidbody>().useGravity = true;
            item.GetComponent<AnimalAI>();
        }

    }

    void Update ()
    {
        if(carrying == false)
        {
            if(Input.GetAxis("Fire1") != 0 && (guide.transform.position - transform.position).sqrMagnitude < range * range)
            {
                Pickup();
                carrying = true;
            }
        }

        else if(carrying == true)
        {
            if(Input.GetAxis("Fire1") != -1)
            {
                Drop();
                carrying = false;
            }
        }
    }

    void Pickup()
    {
        if (item == null)
            return;
        else
        {
            item.GetComponent<Rigidbody>().useGravity = false;
            item.GetComponent<Rigidbody>().isKinematic = true;
            item.transform.position = tempParent.transform.position;
            item.transform.rotation = tempParent.transform.rotation;
            item.transform.parent = tempParent.transform;
        }
    }

    void Drop()
    {
        if (item == null)
            return;
        else
        {
            item.GetComponent<Rigidbody>().useGravity = true;
            item.GetComponent<Rigidbody>().isKinematic = false;
            item.transform.parent = null;
            item.transform.position = tempParent.transform.position;
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.gameObject.CompareTag("Pickups"))
        {
            item = null;
        }
        else
        {
            if (other.gameObject.CompareTag("Pickups"))
            {
                item = GameObject.FindGameObjectWithTag("Pickups");
                item.GetComponent<Rigidbody>().useGravity = true;
                item.GetComponent<AnimalAI>();
            }
        }
    }
}

Video:

just disable the ParticleSystem component on that object. When the player goes to pick it up, do:

item.getComponent<ParticleSystem>().enabled=true;

Then also, you can set it back to false when the puts the object down.

By the way, your onTriggerEnter code seems kind of strange to me:

    private void OnTriggerEnter(Collider other)
    {
        if(other.gameObject.CompareTag("Pickups"))
        {
            item = GameObject.FindGameObjectWithTag("Pickups");
            item.GetComponent<Rigidbody>().useGravity = true;
            item.GetComponent<AnimalAI>();
        }
    }

instead of
item = GameObject.FindGameObjectWithTag("Pickups");
don’t you think it should just be item = other; ?
Edit: the above code should have been item = other.gameObject;

You know that FindGameObjectWithTag might return any item that has that tag, where as I assume, you want item to be the item that the play is close to. You don’t need to find it because you already know it must be “other”.

Secondly, why do you enable gravity just because the player is near the item?

The other thing is that just performing a getComponent for AnimalAI doesn’t actually do anything since you’re not using the result.

Tried that and I received and error.

I didn’t even look at that. I have a similar script that I started with and well, I missed it. Didn’t throw any errors.

I was able to to play around with the code and i think I see the problem or a problem. When I go to pickup I call a bool. When it is true and the mouse button is held down, the object being carried should go to the empty or tempParent.
What I am seeing is, the bool is constantly flashing on and off. If I remove the button and just use the bool in editor, the object does not go to the tempParent and it pushes the player all over the map.

I was able to assign the particles in another script and I am able to turn them on and off.

What I wish to do is pickup and object that will be sent to an empty that is positioned above the head of the player while holding the button down. When I release the object drops in front of the player and the particles stop.
Note: the animals use navmesh agent to wander around and is controlled through the AnimalAI script. I will attach both and a video of what I have.

AnimalAI Script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class AnimalAI : MonoBehaviour
{
    public float radius;
    public float timer;
    public GameObject fx;

    private Transform target;
    private NavMeshAgent agent;
    private float currentTimer;

    public bool idle;
    public float idleTimer;
    private float currentIdleTimer;


   // private Animation anim;

    void OnEnable()
    {
        agent = GetComponent<NavMeshAgent>();
        //anim = GetComponent<Animation>();
        fx.SetActive(false);
        currentTimer = timer;
        currentIdleTimer = idleTimer;
    }

    private void Update()
    {

        currentTimer += Time.deltaTime;
        currentIdleTimer += Time.deltaTime;
        if(currentIdleTimer >= idleTimer)
        {
            StartCoroutine("switchIdle");
        }

        if(currentTimer >= timer && !idle)
        {
            Vector3 newPosition = RandomNavSphere(transform.position, radius, -1);
            agent.SetDestination(newPosition);
            currentTimer = 0;
        }

        if(idle)
        {
           // anim.CrossFade("idle");
        }
        else
        {
          //  anim.CrossFade("walk");
        }
    }

    IEnumerator switchIdle()
    {
        idle = true;
        yield return new WaitForSeconds(3);
        currentIdleTimer = 0;
        idle = false;
    }

    public static Vector3 RandomNavSphere(Vector3 origin, float distance, int layerMask)
    {
        Vector3 randomDirection = Random.insideUnitSphere * distance;
        randomDirection += origin;

        NavMeshHit navHit;
        NavMesh.SamplePosition(randomDirection, out navHit, distance, layerMask);

        return navHit.position;
    }
   
    public void Stop()
    {
        agent.velocity = Vector3.zero;
    }

    public void Resume()
    {
        currentIdleTimer = 0;
        StartCoroutine("switchIdle");
    }

    private void OnDrawGizmosSelected()
    {
        Gizmos.color = Color.green;
        Gizmos.DrawWireSphere(transform.position, radius);
    }

    public void FeathersOn()
    {
        fx.SetActive(true);
    }
    public void FeathersOff()
    {
        fx.SetActive(false);
    }

}

Updated Carry Script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class GrabCarryObject : MonoBehaviour
{
    public GameObject item;
    public GameObject tempParent;
    public Transform guide;
    public float range;
    public bool carrying;
    AnimalAI animalAI;

    private void OnTriggerEnter(Collider other)
    {
        if(other.gameObject.CompareTag("Pickups"))
        {
            item = other.gameObject;
            item.GetComponent<Rigidbody>().useGravity = true;
            item.GetComponent<AnimalAI>();
        }

    }

    void Update ()
    {
        if(carrying == false)
        {
            if(Input.GetAxis("Fire1") != 0 && (guide.transform.position - transform.position).sqrMagnitude < range * range)
            {
                Pickup();
                carrying = true;
            }
        }

        else if(carrying == true)
        {
            if(Input.GetAxis("Fire1") != -1)
            {
                Drop();
                carrying = false;
            }
        }
    }

    void Pickup()
    {
        if (item == null)
            return;
        else
        {
            item.GetComponent<AnimalAI>().FeathersOn();
            item.GetComponent<Rigidbody>().useGravity = false;
            item.GetComponent<Rigidbody>().isKinematic = true;
            item.transform.position = tempParent.transform.position;
            item.transform.rotation = tempParent.transform.rotation;
            item.transform.parent = tempParent.transform;
        }
    }

    void Drop()
    {
        if (item == null)
            return;
        else
        {
            item.GetComponent<Rigidbody>().useGravity = true;
            item.GetComponent<Rigidbody>().isKinematic = false;
            item.transform.parent = null;
            item.transform.position = tempParent.transform.position;
            item.GetComponent<AnimalAI>().FeathersOff();
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.gameObject.CompareTag("Pickups"))
        {
            item = null;
        }
        else
        {
            if (other.gameObject.CompareTag("Pickups"))
            {
                item = other.gameObject;
                item.GetComponent<Rigidbody>().useGravity = true;
            }
        }
    }
}

Video:

Not sure, but did you check if Input.GetAxis("Fire1") is actually returning what you expect? It’s usually not a good idea to use == or != on a float value because floats are imprecise.

For Fire1, I would use Input.GetButton("Fire1") instead. It will return “true” if the button is held down, and “false” if it’s not held down. Then you avoid the float comparison altogether.