Send Message not receiving from more than one object.

I have the following script on an object:

private var dist = 0;
var distance = 100;
var Target : Transform;
var obj : GameObject;
var options : GameObject;
	
function Update () {
	Target = GameObject.FindWithTag("MainCamera").transform;
	
	options = GameObject.FindWithTag("options");
	
	var dist : float = Vector3.Distance(Target.position, transform.position);
	
	if(dist <= distance){
		obj.SendMessage("Selected");
		options.SendMessage("inRange");
	}else{
		options.SendMessage("outRange");
	}
}

it works fine, sending the message to this script and doing what it’s suppose too…

var opt : GameObject;

function inRange () {
	opt.SetActiveRecursively(true);
}
function outRange () {
	opt.SetActiveRecursively(false);
}

but if i duplicate the object with the first script when i come close to the duplicated object it doesn’t work! it still sends the message to “obj” but not “options” “obj” is a child of the object with the first script and is duplicated with it, but “options” is part of my main camera and is the only one with the tag and script. if i delete the first object with the first script it then works with the duplicated copy that it didn’t work with originally… if i duplicate others it always only works with one… i’m confused! please help!

You need to assign variables to the objects. Having multiple objects with the name “object” can confuse the script so it tries to trigger the script for each one with the same name which can freeze the script. Your best bet is assigning each as object1, object2, object3, etc and having each script assigned to each object reflect that.

solved it! because the object was far from one city it was sending the message outRange even when close to a city sending inRange so i just needed it to stop sending outRange at a slightly further distance it sent inRange