 # How would I make lua set spawn location for table(or multiple vetors)?

So I am making a gamemode and I am at the last part and I can’t figure out how to make it set the spawn point to the locations. I got them spawning I just need the spawn point to hit the vectors, or unless I messed up completely. So its like this:

local spawnPos = {
Vector(-100.734840,-1274.259888,-79.968750),
Vector(-1803.711670,-1491.910645,-79.968750),
Vector(-1890.346436,975.450745,-79.392471)
}

function getBestSpawn()
local bestSpawn = Vector(0,0,0)
local closestDistance = 0
if table.Count(ents.FindByClass(“npc_zombie”)) == 0 then
return spawnPos[math.random(1,table.Count(spawnPos)]
end

``````for k, v in pairs(spawnPos) do
local closestZombieDistance = 1000000
for a, b in pairs(ents.FindByClass("npc_zomebie")) do
if b:GetPos():Distance(v) &lt; closestZombieDistance then
closestZombieDistance = b:GetPos():Distance(v)
end
end
end
if closestZombieDistance &gt; closestDistance then
closestDistance = closestZombieDistance
bestSpawn = v
end
``````

end

If you want full code here.

``````

local spawnPos = {
Vector(-100.734840,-1274.259888,-79.968750),
Vector(-1803.711670,-1491.910645,-79.968750),
Vector(-1890.346436,975.450745,-79.392471)
}

function getBestSpawn()
local bestSpawn = Vector(0,0,0)
local closestDistance = 0
if table.Count(ents.FindByClass("npc_zombie")) == 0 then
return spawnPos[math.random(1,table.Count(spawnPos)]
end

for k, v in pairs(spawnPos) do
local closestZombieDistance = 1000000
for a, b in pairs(ents.FindByClass("npc_zomebie")) do
if b:GetPos():Distance(v) < closestZombieDistance then
closestZombieDistance = b:GetPos():Distance(v)
end
end
end

if closestZombieDistance > closestDistance then
closestDistance = closestZombieDistance
bestSpawn = v
end
end

``````