Hello i am getting a null error when my player tries to collide with a coin

Hello i am getting a null error when my player tries to collide with a coin

The error comes from this code and the error is saying

ArgumentNullException: Value cannot be null.
Parameter name: source
UnityEngine.AudioSource.Play () (at :0)
CollectCoin.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/Colectables/CollectCoin.cs:9)
using UnityEngine;

public class CollectCoin : MonoBehaviour
{
    public AudioSource coinFX;

    void OnTriggerEnter(Collider other)
    {
        coinFX.Play();
        ColectableControl.coinCount += 1;
        this.gameObject.SetActive(false);
    }
}

The reason why this happened is that you tried to access a method from coinFX but you didn’t assign an Audio Source to it.

You’ve made coinFX public, so you need to drag an Audio Source to coinFX field in the Inspector window.

If it helps, here’s an example: