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

How do I make it so that multiple parts are selected at random to spawn zombies?

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

0

Just use math.random(minValue, maxValue)

1 answer

Your doing a for loop and your counting your spawn areas.. That's nice.. but your not doing anything with your count. As far as your spawn function goes.. Your simply spawning Zombies.

From what I can see your not even using the for loop even though its running.

I would suggest that you make an empty array.. and then randomly select 10 spawns and add them to the array.

From there you can use your spawn function to spawn zombies from the referenced spawn areas in the array.

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