How to enable TextMeshPro text through a script?

Refer to question I don’t know what to put here.
Trying to make a buying system to clear doors and buy weapons but can’t get text to appear anyone know the problem?
(There are no errors)

Code:

 using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using TMPro;
    
    //using UnityEngine.;
    public class OpenDoor : MonoBehaviour
    {   public GameObject Obstacle;
        public TextMeshProUGUI buyprompt;
        // Start is called before the first frame update
        void Start()
        {  // buyprompt = Obstacle.AddComponent <TextMeshPro> ();
           //buyprompt.activeSelf = false;
        }
    
        // Update is called once per frame
        void Update()
        {
            
        }
    void OnTriggerEnter (Collider other) {
        if(other.tag == "Player") {
        buyprompt.enabled = true;
         }
     }
    
    
    }

Did you drag the text into the public variable slot? Also is it visible normally in the game without turning it off? You could also check if your OnTriggerEnter function ever calls, you can put a debug.log in there or something.

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

public class OpenDoor : MonoBehaviour
{
    public GameObject Obstacle;
    public TextMeshProUGUI buyprompt;

    // Start is called before the first frame update
    void Start()
    {  
        buyprompt = gameObject.GetComponent<TextMeshProUGUI>(); //TextMeshProUGUI component should be on the same gameobject where this script is placed (don't forget to set your "Obstacle" gameobject from the inspector)
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player")
        {
            buyprompt.enabled = true;
        }
    }
}

Try this