How do i make my instantiated objects reference an already existing script? c#

Hello! I’m creating a small 2 game (For my first time) which consists of a Duck picking up lettuces that spawns from the sky (with Instantiate) but if the player doesn’t pick up the lettuce before it hits the ground you will lose time.

It Looks like this
113657-2018-03-25-19-43-28.gif

The problem is i can’t reference my timer script from the spawned objects and make them lower the Time Remaining, i’ve been searching for 2-3 hours already and can’t get it to work :frowning: .
(I can’t make the lettuces disappear when the player picks them up too since i don’t know how to reference the player)

I already tried doing this

TimerScript timerScript = GetComponent<TimerScript>();
timerScript.Tempsrestant -= 1f;
//Tempsrestant = RemainingTime

But i get “NullReferenceException: Object reference not set to an instance of an object
LettuceBehaviour.Update () (at Assets/Lettuces/LettuceBehaviour.cs:19)”

I really need help on that one please. :slight_smile:

Thanks in advance.

Alright nevermind, i managed to do it after 3 hours.

GameObject gameObjectt = GameObject.Find("Sol");
            timerScriptt = gameObjectt.GetComponent<TimerScript>();

I got it now.