Hello, I made a script where if the round ends teleports all the players to the lobby spawns. I defined everything but can't seem to find an issue. It gives me and error.
error:
16:06:24.217 - ServerScriptService.MainScript:364: attempt to get length of global 'lobbyspawns' (a nil value)
here is the section of script that matters
-- Teleport players back to lobby and remove tools.
lobbyspawns = {}
for _, v in pairs(game.Workspace:WaitForChild("Lobby"):GetChildren()) do
if v ~= nil and v.Name == "SpawnLocation" then
table.insert(lobbyspawns, v)
end
print (#lobbyspawns)
end
end
for _, player in pairs(aliveplayers)do
if player ~= nil then
awardpoints(player, 2)
if player.Character ~= nil then
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid ~= nil then
humanoid:UnequipTools()
end
end
local randomspawn = lobbyspawns[math.random(1, #lobbyspawns)]
print(#lobbyspawns)
player.Character:MoveTo(randomspawn.Position)
local backpack = player:FindFirstChild("Backpack")-- Remove tools.
if backpack ~= nil then
backpack:ClearAllChildren()
end
end
end
the lobby name is "Lobby" and the children are names SpawnLocation. however when I try to teleport them it doesn't work and a got that error.
How can I get this to work?

4 comments
Can you tell us which line it is?
yeah, sorry, its line 19
Can you include enough of your script that we actually know everything that's going on? The context of the chunk of code matters a lot.
its a pretty big amount of code, i figured all thats needed would be this since this is where the issues is and where the issue is called.