# MC Duplicate with random location in set range

**URL:** https://forum.kirupa.com/t/mc-duplicate-with-random-location-in-set-range/158771
**Category:** flash
**Created:** [August 11, 2005, 6:45pm UTC](https://forum.kirupa.com/t/mc-duplicate-with-random-location-in-set-range/158771 "2005-08-11T18:45:22Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![imNotGreg](https://avatars.discourse-cdn.com/v4/letter/i/b3f665/32.png) [@imNotGreg](https://forum.kirupa.com/u/imNotGreg)
#### Post date: [August 11, 2005, 6:45pm UTC](https://forum.kirupa.com/t/mc-duplicate-with-random-location-in-set-range/158771/1 "2005-08-11T18:45:22Z")

</div>

Hey all!:pirate3:

Im having a bit of a problem with duplicating a movieclip.  
Im an AS noobie, so dont kill me for stupid mistakes lol.  
Heres what im trying to do:  
I have a button, when the \<Insert\> key is pressed and if the variable money at root is higher or equal, then make the variable “vpill” equals 1 and duplicate the MC “pill”.  
Heres the code i have for that:

```auto

on (keyPress "<Insert>"){
	if (_root.money >= 1000){
		_root.vpill = 1;
		_root.money -= 1000;
		duplicateMovieClip(_root.pill, "pill"+1, _root.pill);
	}
}

```

As for the MC “pill”, what i want is if the variable “vpill” equals 1 then at a random location (in a set range), place the mc, and if hitTest is true with “player” then \_root.speed -= 1; make “vpill” equal 0 and remove the duplicated MC.  
Heres the code i have on “pill” MC:

```auto

onClipEvent (load) {
	randomNum=function(Minimum,Maximum){
		return Minimum+Math.random()*(Maximum-Minimum);
	}
	if (_root.vpill == 1) {
		pillx = randomNum(220, 480);
		pilly = randomNum(70, 330);
		this._x = pillx;
		this._y = pilly;
		if (this, hitTest(_root.player)) {
			_root.speed -= 1;
			this.removeMovieClip();
			_root.vpill == 0;
		}
	}
}

```

NOTE: Variables are all placed in the root.

Thx in advance!  
If u dont understand something, feel free to ask. THX! :crazy:
