X axis, y u no work?

Vertical Y axis works, but even on a separate js file I can’t make this work. I just started to use js and I’m not familiar with it. Help?
#pragma strict

var moveLeft : KeyCode;
var moveRight : KeyCode;

var speed : float = 20;

function Update ()
	if (Input.GetKey(moveLeft))
		rigidbody2D.velocity.x = speed;
	else if (Input.GetKey(moveRight))
		rigidbody2D.velocity.x = speed *-1;
		rigidbody2D.velocity.x = 0;

Are you initializing the ‘moveLeft’ and ‘moveRight’ vars somewhere?

for example:
var moveLeft = KeyCode.LeftArrow

You can also write instead:

rigidbody2D.velocity.x = speed * Input.GetAxis ("Horizontal");

GetAxis returns a number from -1 to 1 based on the input.
It can save you some precious lines of code.

I’m stuck with the same problem with exactly the same code, the player moves on the y axis but doesn’t move on the x.

Have you managed to get your player moving on the x axis?