Up and down movement via Javascript

i'm designing a small game in which i need a puzzle piece to go up and down, but i can't seem to get it to work. here is the code i'm using.

  var toplimit : float = 31;
var botlimit : float = -31;

var goUp : float = 300;

var goDown : float = -300;

function Update () {

rigidbody.AddForce(Vector3(0,goUp,0));

if (transform.position.y < toplimit)
rigidbody.AddForce(Vector3(0,goDown,0));

if (transform.position.y > botlimit)
rigidbody.AddForce(Vector3(0,goUp,0));
}

can anyone see an issue? or think of a better way to do it? :)

thanks for any help

Try this:

var toplimit : float = 31;
var botlimit : float = -31;
var goUp : float = 300;
var goDown : float = -300;

function Awake()
{
    rigidbody.AddForce(Vector3(0, goUp, 0));
}

function Update() 
{
    if (transform.position.y > toplimit)
    {
        rigidbody.velocity = Vector3.zero;
        rigidbody.AddForce(Vector3(0, goDown, 0));
    }
    if (transform.position.y < botlimit)
    {
        rigidbody.velocity = Vector3.zero;
        rigidbody.AddForce(Vector3(0, goUp, 0));
    }
}

well if i get right is a puzzle game, this means that the objects dont need to use the gravity or other physics attributes, if i guess right i propose you to fix the position

i'll write an example to make it go up and down between this points

var toplimit : float = 31;
var botlimit : float = -31;

bool goingup = false;

function Update()
{
   //if the position goes over the top limit then the goingup is false, meaning is not going up, then is going down
   if(transform.position.y+1>toplimit)
      goingup=false;
   //if the position goes below the bottom limit then the goingup is true, meaning is going up from now on
   if(transform.position.y-1<botlimit)
      goingup=true;

   //going up... is self descriptive
   if(goingup)
   {//if is true then it goes 1 position up
      transform.position.y +=1;
   }
   else
   {//if is false then it goes 1 position down
      transform.position.y -=1;
   }
}

for puzzle games, is easier to fix the position hope this is the answer you looking for =)