What am I doing wrong

hero = nil
enemies = nil
bgLines = nil
explosion = nil

GAME_PLAYING = 0
GAME_DEAD = 1
state = GAME_PLAYING

-- Use this function to perform your initial setup
function setup()
    state = GAME_PLAYING

    iparameter("BackgroundSpawnRate",0,3,2)

    hero = Invader()
    hero.position = vec2(WIDTH/2,HEIGHT/2)

    enemies = EnemyHorde()
    enemies.heroBullets = hero.bullets

    bgLines = StreamingLines()
    
    highscore = readLocalData("highscore")

    if not highscore then
        highscore = 0
    end
end

function touchingAtPos()
    if CurrentTouch.state == BEGAN or 
       CurrentTouch.state == MOVING then
        return vec2( CurrentTouch.x, CurrentTouch.y )
    end 

    return nil
end

-- This function gets called once every frame
function draw()
    displayMode(FULLSCREEN)
    background(0, 0, 0, 255)
sprite("Documents:minecraft", WIDTH/2, HEIGHT/2)
    bgLines.spawnRate = BackgroundSpawnRate

    bgLines:update()
    bgLines:draw()

    if state == GAME_PLAYING then 
        -- Process touch
        touch = touchingAtPos()
        if touch then
            hero.position.x=CurrentTouch.x
            hero.position.y=CurrentTouch.y
            end
        end
        
end
        if enemies.killCount == 5 then
            enemies.spawnPattern = ENEMY_SPAWN_HARD
        end

        enemies:draw()

        hero:draw()

        -- Check if hero is hit
        for i,v in ipairs(enemies.units) do
            if v:dist(hero.position) < 40 then
                state = GAME_DEAD
                explosion = Explosion(hero.position)
                saveLocalData("highscore", highscore)
                
                if score >= highscore then
                    didGetHighScore = true
                end
            end
    end
--->    elseif state == GAME_DEAD then
        if explosion then
            explosion:draw()
            if explosion:isDone() then
                explosion = nil
            end
        end
        
        fontSize(60)
        textMode(CENTER)
        text("GAME OVER",WIDTH/2,HEIGHT/2)
        
        if didGetHighScore == true then
            fontSize(40)
            text("NEW HIGH SCORE!",WIDTH/2,HEIGHT/2 - 80)
        end
        
    end
    
    -- Draw scores
    score = enemies.killCount * 100
    fill(255)
    font("Futura-CondensedExtraBold")
    fontSize(30)
    textMode(CORNER)
    text("Score: "..score, 10, HEIGHT - 50)
    
    -- update high score
    if score > highscore then
        highscore = score
    end
    
    hs = "High Score: "..highscore
    hswidth = textSize(hs)
    text(hs, WIDTH - hswidth - 10, HEIGHT - 50)
end

```


It says  expected near elseif on line 80
What do I do
The arrow shows where it is
Arrows not part of code

Here is a corrected version. You had an extra end statement in the draw() routine. I also changed iparameter to parameter.number. The function Invader() isn’t included, so I can’t help any further.
One thing that would help when there is an error is to format the code correctly so you can see where the end statements don’t match.


hero = nil
enemies = nil
bgLines = nil
explosion = nil
 
GAME_PLAYING = 0
GAME_DEAD = 1
state = GAME_PLAYING
 
-- Use this function to perform your initial setup
function setup()
    state = GAME_PLAYING

    parameter.number("BackgroundSpawnRate",0,3,2)
 
    hero = Invader()
    hero.position = vec2(WIDTH/2,HEIGHT/2)
 
    enemies = EnemyHorde()
    enemies.heroBullets = hero.bullets
 
    bgLines = StreamingLines()
     
    highscore = readLocalData("highscore")
 
    if not highscore then
        highscore = 0
    end
end
 
function touchingAtPos()
    if CurrentTouch.state == BEGAN or
       CurrentTouch.state == MOVING then
        return vec2( CurrentTouch.x, CurrentTouch.y )
    end
 
    return nil
end
 
-- This function gets called once every frame
function draw()
    displayMode(FULLSCREEN)
    background(0, 0, 0, 255)
    sprite("Documents:minecraft", WIDTH/2, HEIGHT/2)
    bgLines.spawnRate = BackgroundSpawnRate
 
    bgLines:update()
    bgLines:draw()
 
    if state == GAME_PLAYING then
        -- Process touch
        touch = touchingAtPos()
        if touch then
            hero.position.x=CurrentTouch.x
            hero.position.y=CurrentTouch.y
        end
         
        if enemies.killCount == 5 then
            enemies.spawnPattern = ENEMY_SPAWN_HARD
        end
 
        enemies:draw()
 
        hero:draw()
 
        -- Check if hero is hit
        for i,v in ipairs(enemies.units) do
            if v:dist(hero.position) < 40 then
                state = GAME_DEAD
                explosion = Explosion(hero.position)
                saveLocalData("highscore", highscore)
                 
                if score >= highscore then
                    didGetHighScore = true
                end
            end
        end
    elseif state == GAME_DEAD then
        if explosion then
            explosion:draw()
            if explosion:isDone() then
                explosion = nil
            end
        end
         
        fontSize(60)
        textMode(CENTER)
        text("GAME OVER",WIDTH/2,HEIGHT/2)
         
        if didGetHighScore == true then
            fontSize(40)
            text("NEW HIGH SCORE!",WIDTH/2,HEIGHT/2 - 80)
        end
         
    end
     
    -- Draw scores
    score = enemies.killCount * 100
    fill(255)
    font("Futura-CondensedExtraBold")
    fontSize(30)
    textMode(CORNER)
    text("Score: "..score, 10, HEIGHT - 50)
     
    -- update high score
    if score > highscore then
        highscore = score
    end
     
    hs = "High Score: "..highscore
    hswidth = textSize(hs)
    text(hs, WIDTH - hswidth - 10, HEIGHT - 50)
end

.@Mnjk78lg

.@Anonycode has a code updater here: http://twolivesleft.com/Codea/Talk/discussion/2208/project-code-syntax-updater

If you or anyone else want to use it; it can make changes to your code like what .@dave1707 did (you know like how he altered iparameter to parameter.integer?).

Thank you for your help I really appreciate it.