Hello, I’m making a zombie waves system but Im confused about what to do next. How the zombies spawn, is by 15 parts organized in the line. If there are less then 15 of a type of zombie spawning, I want them to spawn as close to the center as possible. But if there are more than 15 zombies, then I want a full line to spawn, and repeat until all the zombies are spawned. I already organized the table that has the closest ones in it, but now I need to implement the availability and I have no idea how to do that.
If needed here’s the script:
local distances = {}
for i,zombieSpawnPosition in pairs(possibleZombieSpawnPositions:GetChildren()) do
local distanceValue = Instance.new("NumberValue",zombieSpawnPosition)
distanceValue.Value = (centerZombieSpawnPosition - zombieSpawnPosition).Magnitude
distanceValue.Name = "Distance"
local availabilityValue = Instance.new("BoolValue",zombieSpawnPosition)
availabilityValue.Value = true
table.insert(distances,{zombieSpawnPosition,distanceValue.Value,availabilityValue})
end
for i,zombieSpawnPosition in pairs(possibleZombieSpawnPositions:GetChildren()) do
table.sort(distances,function(a,b)
return a[2] < b[2]
end)
print(table.unpack(distances))
end
if zombies <= 15 then
else
for index4,spawnLine in pairs() do
end
end
In the line of 15 possible spawn parts. I made this in the script right here:
for i,zombieSpawnPosition in pairs(possibleZombieSpawnPositions:GetChildren()) do
local distanceValue = Instance.new("NumberValue",zombieSpawnPosition)
distanceValue.Value = (centerZombieSpawnPosition - zombieSpawnPosition).Magnitude
distanceValue.Name = "Distance"
local availabilityValue = Instance.new("BoolValue",zombieSpawnPosition)
availabilityValue.Value = true
table.insert(distances,{zombieSpawnPosition,distanceValue.Value,availabilityValue})
end
Well, assuming that you loop over each zombiePosition to spawn the zombies, just set the availabilityValue to false either through the table or by indexing the child of the spawn position
for i,zombieSpawnInfo in pairs(distances) do
local zombie = replicatedStorage:WaitForChild("Zombies"):WaitForChild("NormalZombie"):Clone()
zombie.HumanoidRootPart.CFrame = zombieSpawnInfo[1][zombieSpawnInfo[#zombieSpawnInfo]]
zombieSpawnInfo[3].Value = false
end
for _, zombieSpawnInfo in distances do
local zombie = replicatedStorage.Zombies.NormalZombie:Clone()
zombie:PivotTo(CFrame.new(zombieSpawnInfo[1])]
zombieSpawnInfo[3].Value = false
end
I’m sorry but something is not working and I don’t know what it is
while wavesStarted == true do
local waveInfo = workspace:WaitForChild("WaveInfo")
local currentWaveZombies = waveInfo:WaitForChild("Wave"..wave.."Zombies")
updateClientIntermissionText.Value = "Spawning zombies"
local centerZombieSpawnPosition = possibleZombieSpawnPositions:WaitForChild("CenterZombieSpawnPosition")
for i,zombieType in pairs(currentWaveZombies:GetChildren()) do
local zombies = zombieType.Value
if zombieType.Name == "NormalZombies" then
for index2 = zombies,1,-1 do
local distances = {}
for i,zombieSpawnPosition in pairs(possibleZombieSpawnPositions:GetChildren()) do
local distanceValue = Instance.new("NumberValue",zombieSpawnPosition)
distanceValue.Value = (centerZombieSpawnPosition - zombieSpawnPosition).Magnitude
distanceValue.Name = "Distance"
local availabilityValue = Instance.new("BoolValue",zombieSpawnPosition)
availabilityValue.Value = true
table.insert(distances,{zombieSpawnPosition,distanceValue.Value,availabilityValue})
end
for i,zombieSpawnPosition in pairs(possibleZombieSpawnPositions:GetChildren()) do
table.sort(distances,function(a,b)
return a[2] < b[2]
end)
print(table.unpack(distances))
end
if zombies <= 15 then
for i,zombieSpawnInfo in pairs(distances) do
if zombieSpawnInfo[3].Value == true then
local zombie = replicatedStorage.Zombies.NormalZombie:Clone()
zombie.HumanoidRootPart.CFrame = zombieSpawnInfo[1].CFrame
zombieSpawnInfo[3].Value = false
end
end
else
for index4,spawnLine in pairs() do
end
end
end
elseif zombies.Name == "SpeedZombies" then
elseif zombies.Name == "SlowZombies" then
elseif zombies.Name == "MiniBossZombies" then
end
end
for i = waveLength,1,-1 do
for index2,player in pairs(players) do
if player then
character = player.Character
if character then
if not character:FindFirstChild("GameTag") then
table.remove(players,index2)
end
end
else
table.remove(players,index2)
end
end
updateClientIntermissionText.Value = "Wave "..wave..": "..i.." seconds left"
if #zombiesFolder:GetChildren() == 0 then
updateClientIntermissionText.Value = "Wave "..wave.." completed"
break
end
end
if #zombiesFolder:GetChildren() ~= 0 then
updateClientIntermissionText.Value = "Starting next wave"
wait(3)
end
wave = wave + 1
end