How do I make text stay for a couple of seconds and disappear in the scene after a couple seconds of scene

I am gonna have text in my scene say this :

The score to reach for this level is : 2054

Text stay in the scene for a couple of seconds than disappear in a couple of seconds

Use a coroutine and a CanvasGroup to set the opacity.

Something like:

IEnumerator ShowMessageCoroutine(string message, float timeToShow = 10)
    canvasGroup.alpha = 1;
    textElement.text = message;
    while (timeShown < timeToShow)
        timeShown += Time.deltaTime;
        yield return null;
    canvasGroup.alpha = 0;
    textElement.text = "";

You start it with:

void ShowMessage(string message, float timeToShow = 10)
    StartCoroutine(ShowMessageCoroutine(message, timeToShow));