How to make moving tiles in side scroller?

I have a tile prefab. The user has to jump from tile to tile. I want to know how to make a script so that if attached to a tile, it will make that tile move back and forth along the x Axis. How would I do this?

private bool movingLeft;

void Update (){
    if(transform.position.x < -4){
        movingLeft = false;
    if(transform.position.x > 4){
        movingLeft = true;
    } else {