Cant Get Constant Movement In SNAKE GAME Please Advise!

So basically my question is, how do i make it constantly move foreward or sideways, ive tried for loops if statements within if statements, and cannot understand why it still is only moving one peice at a time.

i have this script on the PLAYER with no other dependancy

and i have another script on the food prefab with the positions of them for collisions.

i am trying to use as little unity to develope this.

///script start

var cube : GameObject;//bpdy of the snake
var keyPressUp = false;
var keyPressDown = false;
var keyPressRight = false;
var keyPressLeft = false;
var tailLength : int;// later on
var food : GameObject;
var foodpos : foodpos;

static var charx : float;
static var chary : float;

function Start(){
//create the food random location within the grid system
Instantiate(food, Vector3(Random.Range(-12 / 1, 12 / 1), Random.Range(-8 / 1, 10 / 1)), Quaternion.identity);

}

function FixedUpdate()
{
//boundary for game movement
transform.position.x = Mathf.Clamp(transform.position.x, -13, 13);
transform.position.y = Mathf.Clamp(transform.position.y, -9, 11);
}

function Update()
{

    //mark characters x y coordinates for collision
    charx = transform.position.x;
    chary = transform.position.y;

//if player hits position of the food x and y
if(transform.position == Vector3(foodpos.foodx,foodpos.foody,0))
{
    Destroy(GameObject.FindWithTag("food"));//destroy the food
    Instantiate(food, Vector3(Random.Range(-12 / 1, 12 / 1), Random.Range(-8 / 1, 10 / 1)), Quaternion.identity);//create the food
    
    //check what direction player is going to place tail on correct side
    if(keyPressLeft == true)
    {
        Instantiate(cube, Vector3(transform.position.x +1,transform.position.y,0), Quaternion.identity);
    }
    if(keyPressRight == true)
    {
        Instantiate(cube, Vector3(transform.position.x - 1,transform.position.y,0), Quaternion.identity);
    }
    if(keyPressUp == true)
    {
        Instantiate(cube, Vector3(transform.position.x,transform.position.y - 1,0), Quaternion.identity);
    }
    if(keyPressDown == true)
    {
        Instantiate(cube, Vector3(transform.position.x,transform.position.y +1,0), Quaternion.identity);
    }
}

    //If Button W is down and D A S are not then move
    if (Input.GetKeyDown("w") && keyPressRight == false && keyPressLeft == false && keyPressDown == false ) 
    {
        //mark last positions
        lastPosy = transform.position.y;
        lastPosx = transform.position.x;
        print (" lastposy : " + lastPosy);
        //move one position up
        transform.position.y += 1;
        keyPressUp = true;
        GridCheck();
    }
    //If Button S is down and D A W are not then move
    if (Input.GetKeyDown("s") && keyPressRight == false && keyPressLeft == false && keyPressUp == false) 
    {
        //mark last positions
        lastPosy = transform.position.y;
        lastPosx = transform.position.x;
        print (" lastposy : " + lastPosy);
        //move one position down
        transform.position.y += -1;
        keyPressDown = true;
        GridCheck();
    }
    //if Button A is down and S D W are not then move
    if (Input.GetKeyDown("a") && keyPressDown == false && keyPressRight == false && keyPressUp == false) 
    {
        //mark last positions
        lastPosy = transform.position.y;
        lastPosx = transform.position.x;
        print (" lastposx : " + lastPosx);
        transform.position.x += -1;
        //move one position left
        keyPressLeft = true;
        GridCheck();
    }
    //If Button D is down and A S W are not then move
    if (Input.GetKeyDown("d") && keyPressLeft == false && keyPressDown == false && keyPressUp == false) 
    {
        //mark last positions
        lastPosy = transform.position.y;
        lastPosx = transform.position.x;
        print (" lastposx : " + lastPosx);
        //move one position right
        transform.position.x += 1;
        keyPressRight = true;
        GridCheck();
         

    }


    //Release button check
    if (Input.GetKeyUp("w")) 
    {
    keyPressUp = false;
    }
    if (Input.GetKeyUp("s")) 
    {
    keyPressDown = false;
    }
    if (Input.GetKeyUp("a")) 
    {
    keyPressLeft = false;
    }
    if (Input.GetKeyUp("d")) 
    {
    keyPressRight = false;
    }

}
//if player hits boundary transform to opposite side
function GridCheck()
{
//if hit boundary x go to opposite side of grid
if(transform.position.x == -13 && keyPressLeft == true)
{
transform.position.x = 13;
}
if(transform.position.x == 13 && keyPressRight == true)
{

        transform.position.x = -13;

    }
           
    //if hit boundary y go to opposite side of grid                
if(transform.position.y == -9 && keyPressDown == true)
    {
        transform.position.y = 11;
    }
            if(transform.position.y == 11 && keyPressUp == true)
    {
        transform.position.y = -9;
    }
}

///script end

'//If Button W is down and D A S are not then move
if (Input.GetKeyDown(“w”) && keyPressRight == false && keyPressLeft == false && keyPressDown == false )
{
//mark last positions
lastPosy = transform.position.y;
lastPosx = transform.position.x;
print (" lastposy : " + lastPosy);
//move one position up
transform.position.y += 1;
keyPressUp = true;
GridCheck();
}

this is the movement part, where this moves up (Y DIRECTION +1) every time the W key is pushed. im new to this stuff. hope i gave enough information.

With constant movement, pressing left should make it turn left, and then continue moving left after you let go of that key, yes? This means the code should remember the last key pressed, and use that for movement. All the key-reading is only to set it. Something like:

Vector3 moveDir; // global

if( player says up ) movedir = Vector3.forward;
if( player says right ) movedir = Vector3.right;
  ...
// NOTE: moveDir will stay like that forever until they pick a new one

// move:
transform.position += moveDir;

Of course, this will move every frame, which is much too quickly. An old trick is to set nextMovetime = Time.time + 0.25f; and add a big if(Time.time>nextmoveTime) in front of where you actually move. Or, use moveDir * Time.deltatime for smooth (but most snake games prefer to move in ticks.)

A comment: your keyPressLeft remembers if the user pressed left, but the code resets it when they let go of left, defeating the purpose. If you think about the goal, keyPressLeft should stay true until they press some other movement key. When my code gets out of control like this, I comment it all out (so I can use it as a reference) and rewrite from scratch, with cut&pastes as needed.

Not sure if that helps, but if I wanted to create a Snake-like game, I’d start with something like this:

function Update() {
transform.Translate(transform.forward * Time.deltaTime);

if(Input.GetKeyDown(KeyCode.A))
transform.forward = Vector3.Slerp(Vector3.forward, - Vector3.right, turnSpeed * Time.deltaTime);


if(Input.GetKEyDown(KeyCode.S))
transform.forward = Vector3.Slerp(Vector3.forward, Vector3.right, turnSpeed * Time.deltaTime);
}

It should make the object this is attached to move constantly forward and when you press ‘A’ or ‘S’ it should turn 90° left or right.