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

Why does this script error?

Asked by 9 years ago
while true do
    wait(300) -- 5 min
    m = math.random(1,2)
    if m == 1 then
        local c = game.ServerStorage["Big Fields"]:Clone()
        c.Parent = workspace
        for i,v in pairs(game.Players:GetPlayers()) do
            v.Character:MoveTo(c.Bases.Base.Position)
    elseif m == 2 then -- ERROR LINE
        local c = game.ServerStorage.map:Clone()
        c.Parent = workspace
        for i,v in pairs(game.Players:GetPlayers()) do
            v.Character:MoveTo(c.Position)

        end
            end



            end
end
end


The errored line is the one with the green comment that says "ERROR LINE" It has a red line under it, and when I hover my mouse over it to check the problem, it says "expected 'end' (to close 'do' at line 7) got 'elseif'"

Why does it keep erroring?

1 answer

Log in to vote
2
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

Well, you had the right number of 'end's, but the wrong placement. You need one of them to close the for loop on line 7, so the end should be on line 9. Here:

while true do
    wait(300)
    m = math.random(1,2)
    if m == 1 then
        local c = game.ServerStorage["Big Fields"]:clone()
        c.Parent = game.Workspace
        for i,v in pairs(game.Players:GetPlayers()) do
            v.Character:MoveTo(c.Bases.Base.Position)
        end
    elseif m == 2 then
        local c = game.ServerStorage.map:Clone()
        c.Parent = game.Workspace
        for i,v in pairs(game.Players:GetPlayers()) do
            v.Character:MoveTo(c.Position)
        end
    end
end
Ad

Answer this question