Instantiate a prefab at the Mouse's position?

I have been trying to instantiate a prefab at the position of the cursor, like this:

However the when I click the prefab isn’t instantiating at the exact position of the cursor, It is off most always and sometimes it won’t even show up in front of the camera.

my code is:

function Update () {
var MousePosition = Input.mousePosition;
    if (Input.GetMouseButtonDown(0)) 
    {
        var ObjectPosition = Camera.main.ScreenToWorldPoint(MousePosition);
    
        ObjectPosition.y = 0;
    
        Instantiate(Object, ObjectPosition, Quaternion.identity);
    }
}

This script is attached to the Main Camera if that helps any. I am trying to instantiate the prefab on a plane, also.

ScreenToWorldPoint(MousePosition) doesn’t necessarily give you the coordinate you want (but since your question is a bit vague, I don’t exactly know what you want…the mouse position is generally in 2D, while the world is 3D…do you want to spawn the object on a terrain?)

I’d use a raycast and instantiate the object on the intersection of the ray and whatever plane the object should sit on.