I have multiple parts placed down so that zombies can spawn there. But I want to make it so that every time the zombies spawn, they will spawn on one third of the selected random parts.
For example, there are 30 parts and every time the zombies spawn, the script would select 10 random parts and the zombies will spawn there. That means there would be 10 zombies.
I have a script that already randomly selects parts. But they only spawn one zombie all the time. Furthermore, I don't know why but the zombies just stop spawning after a while and it does not output anything.
The script is here:
zombie1 = game.ServerStorage.Zombie1
local spawnable = true
local count = 0
for i, children in pairs(game.Workspace.SpawnAreas.ZombieSpawns:GetChildren()) do
if children:IsA("BasePart") then
count = count + 1
end
end
function spawnZombies(spawnTime)
if spawnable then
spawnable = false
for i, v in pairs(game.Workspace.SpawnAreas.ZombieSpawns:GetChildren()) do
v.Name = "ZombieSpawn"..i
local zombie1Copy = zombie1:Clone()
zombie1Copy.Name = "Zombie"
zombie1Copy.Parent = game.Workspace.Zombies
zombie1Copy:MoveTo(game.Workspace.SpawnAreas.ZombieSpawns["ZombieSpawn"..i].Position + Vector3.new(0, 1, 0))
wait(spawnTime)
spawnable = true
end
end
end
spawnZombies(3)
I'm also not really good with for loops and don't even understand much of the spawnZombies function. I've been trying to find many ways to get this to work but I really can't find any other thing.
Please give me some help.

1 comment
Just use math.random(minValue, maxValue)