Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I fix this error that keeps popping up that says "Syntax error: Expected 'end', got 'else.''?

Asked by 3 years ago

This code is just my first game and I am following a tutorial on yt. I have already worked hours on it and even more just doing research and doing everything I can to fix the code. Anyway i get this error message with the following code and really need help to fix it because i will probably give up:

for i = GameLength,0,-1 do

    for x, player in pairs(plrs) do 
        if player then 

            character = player.Character
            -- Left the game

        else
            if character:FindFirstChild("GameTag") then
                -- They are still alive
                print(player.Name.."is still in the game!")

            else
                -- They are dead
                table.remove(plrs,x)

            end
        end

    else <------- THE ERROR IS RIGHT HERE AND SAYS "Error: (111,3) Syntax error: Expected 'end' (to close 'do' at line 93), got 'else''.

            table.remove(plrs,x)
            print(player.Name.."has been removed!")
    end

    wait(1)

end

end

1 answer

Log in to vote
3
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago

Note: I have made comments numbering each loop / if statement.

The reason you are getting the error is because the 'else' keyword does not operate with a 'for' loop, only with an 'if' statement.

for i = GameLength,0,-1 do -- 1
    for x, player in pairs(plrs) do -- 2
        if player then -- 3

            character = player.Character
            -- Left the game

        else -- 3
            if character:FindFirstChild("GameTag") then -- 4
                -- They are still alive
                print(player.Name.."is still in the game!")

            else -- 4
                -- They are dead
                table.remove(plrs,x)

            end -- 4
        end -- 3

        -- Removed else keyword from this location

        table.remove(plrs,x)
        print(player.Name.."has been removed!")
    end -- 2

    wait(1)
    end -- 1
end --< Appears to be an extra 'end' keyword
-- ^^ If you do not have another loop that requires this 'end' keyword, remove it.

Some extra information from Roblox:

Multiple Conditions with Elseif and Else

0
THANK YOU SO MUCH BROOOOOO!!!!! ibestgamer78 0 — 3y
1
If it solved your problem, you should accept the answer. It gives us both reputation. appxritixn 2235 — 3y
Ad

Answer this question