Instantiate only One Object

I am trying to be able to place boards down when they collide with other objects and you click. However if it collides with more than one object it places more than one board in the same spot. How can I change it so that it only places one board? This is the script on the plank that you use to decide where to place it.

void OnCollisionStay(Collision collisionInfo){
	
		if (Input.GetMouseButtonDown(0) && placeone == false){
		
			Instantiate(woodPlank, transform.position,transform.rotation);
			placeone = true;
		}
		
		if (Input.GetMouseButtonUp(0)){
			
		placeone = false;	
		}
	
	}

shouldn’t that do it? Thanks for any help!

Your problem is that you have multiple scripts, all reacting to the same Input.GetMouseButtonDown(0), and each spawning an object.

The easiest solution is to make the bool “placeone” static:

static bool placeone;
// your code

This way, there is only one instance of this bool, which is known (and identical) to all script instances of this class.