How do I Instantiate a prefab at the x axis position of where the UI button was clicked

So right now i have an invisible button in my 3d game scene that when clicked i need to find the right worldspace position to drop the newly instantiated coin. I am close BUT if i don’t click in the center of the button and drop straight down then the prefabs drop in strange places along the x axis. I need to limit the “drop zone” of the instantiated prefab to the width of the button so they only fall onto the playable area of the scene.

//variables
public Button dropButton;
public GameObject coin;
Ray ray;
RaycastHit hit;

// Start is called before the first frame update
void Start()
{
    Button button = dropButton.GetComponent<Button>();
    button.onClick.AddListener(DropCoin);
}

// Update is called once per frame
void Update()
{
}

public void DropCoin()
{
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    if (Physics.Raycast(ray, out hit))
        {
        GameObject instantiatedCoin;
        instantiatedCoin = Instantiate(coin, new Vector3(hit.point.x, 9.5f, 10.5f), Quaternion.identity) as GameObject;
        }
}

}

Is there a ground object behind the button which you expect the raycast to hit? I wonder if it’s hitting something else on the way, like the button. That would mess up x if you have a perspective camera. Try printing hit.transform.name to check.

A fix would be setting the raycast’s latermask to only hit the ground.