# Help With Random X Pos

**URL:** <https://forum.kirupa.com/t/help-with-random-x-pos/305551>\
**Category:** Uncategorized\
**Created:** [February 27, 2010, 3:49am UTC](https://forum.kirupa.com/t/help-with-random-x-pos/305551 "2010-02-27T03:49:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Danny0123](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@Danny0123](https://forum.kirupa.com/u/Danny0123)\
**Post date:** [February 27, 2010, 3:49am UTC](https://forum.kirupa.com/t/help-with-random-x-pos/305551/1 "2010-02-27T03:49:35Z")

</div>

Here’s my code. (It’s a class for a MovieClip which is attached to the stage)

```php
class People extends MovieClip {
    var speed:Number = 2;
    var old:Number = 0;
    var newY:Number = 0;
    var RobotSpeed:Number = 0;
    var xVally:Number;
    function onLoad(){
        rando();
        this._x = xVally;
        this._y = 350;
        speed = Math.round(Math.random(2)+1);
    }
    function onEnterFrame(){
        if(xVally == -10){
            this._x += speed;
            this._xscale = -100;
        }else if(xVally == 710){
            this._x -= speed;
        }
        newY = _root.RobotInstance._y;
        checkRemove();
        this.swapDepths(_root.getNextHighestDepth());
        checkCollision();
        checkY();
    }
    function rando(){
        if(Math.round(Math.random(1,0)) == 1){
            xVally = -10;
        }
        if(Math.round(Math.random(1,0)) == 0){
            xVally = 710;
        }
    }
    function checkRemove(){
        if(this._x > Stage.width+10 && xVally == -10){
            this.removeMovieClip();
        }
        if(this._x < -10 && xVally == 710){
            this.removeMovieClip();
        }
    }
    function checkCollision(){
        var xVal:Number = this._x;
        if(this.hitTest(_root.RobotInstance) && RobotSpeed < 0){
            this.removeMovieClip();
            _root.attachMovie("Bloody", "BloodMC"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:xVal, _y:355});
        }
    }
    function checkY(){
        RobotSpeed = (old-newY);
        old = newY;
    }
        
}

```

It works pretty good, however some of the People, instead of spawning at X 710 or -10, just spawn at X 0 and stay there. What is causing this and more importantly, how can I fix it?
