Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does this script error?

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.