Help with Zombies (they are killing me)

My script spawns zombies as I want, but it does not spawn a random zombie species. I would like my script to spawn zombies of a random species in random amounts. (It spawns one species per zombie spawn instead of a random zombie species at a random spawn, of a random amount)

image

My Scripts

Server script.


local roundModule = require(script.RoundModule)

while wait() do
	roundModule.Intermission("Intermission", 30)
	roundModule.RoundTime("Chooseing Map...", 3)
	
	roundModule.chooseMap()
	
	if workspace:FindFirstChild("CurrentMap") then
		local mapName =workspace.CurrentMap:FindFirstChild("MapName").Value
		local destination = workspace.CurrentMap:FindFirstChild("Spawn")
		
		roundModule.RoundTime("Map Chosen" .. mapName, 3)
		
		roundModule.teleportPlayersInRound(destination)
		
		roundModule.RoundTime("Eradicate All Zombies", 120)
	end

	roundModule.resetPlayers()
	roundModule.cleanUpRound()
end

Module Script

local module = {}

local playersInRound = {}

local replicatedStorage = game:GetService("ReplicatedStorage")
local values = replicatedStorage:WaitForChild("Values")
local clockValue = values:FindFirstChild("Clock")
local statusValue = values:FindFirstChild("Status")

module.spawnZombie = function(rate)
	for i = rate, 0, -1 do
		local zombieFolder = replicatedStorage:FindFirstChild("Zombies")
		local zombies = zombieFolder:GetChildren()
		local numberOfZombies = #zombies

		local randomNumber = math.random(1, numberOfZombies)
		local chosenZombie = zombies[randomNumber]

		if chosenZombie then
			local newZombie = chosenZombie:Clone()
			if workspace:FindFirstChild("CurrentMap") then
				if workspace.CurrentMap:FindFirstChild("ZombieSpawns") then
					local spawns = workspace.CurrentMap.ZombieSpawns:GetChildren()
					local numberOfSpawns = #spawns

					local otherRandomNumber = math.random(1, numberOfSpawns)

					local chosenSpawn = spawns[randomNumber]

					if chosenSpawn then
						newZombie:SetPrimaryPartCFrame(chosenSpawn.CFrame)
						newZombie.Parent = workspace.Zombies
					end
				end
			end
		end
	end
end

module.Intermission = function(status, clock)
	--set the round status and count down
	statusValue.Value = status
	for i = clock, 0, -1 do
		clockValue.Value = i
		wait(1)
	end
	return true
end

module.RoundTime = function(status, clock)
	--set the round status and count down
	statusValue.Value = status
	for i = clock, 0, -1 do
		clockValue.Value = i
		wait(1)
		
		if not playersInRound[1] then
			break
		end
		
		module.spawnZombie(math.random(1, 3))
	end
	return true
end

module.resetPlayers = function()
	--find the player by their name and respawn any still in the map
	for _, v in pairs(playersInRound) do
		local foundPlayer = game.Players:FindFirstChild(v)
		if foundPlayer then
			foundPlayer:LoadCharacter()
		end
	end
	return true
end

module.teleportPlayer = function(player, destination)
	--move the character to the destination (must be an instance with CFrame)
	local character = player.Character or player.CharacterAdded:Wait()
	if character then
		local humanoidRootPart = character:WaitForChild("HumanoidRootPart") 
		if humanoidRootPart then
			humanoidRootPart.CFrame = destination.CFrame
		end
	end
	return true
end

module.teleportPlayersInRound = function(destination)
	--insert the players into the table
	for i, v in pairs(game.Players:GetPlayers()) do
		table.insert(playersInRound, v.Name)
		--teleport the player
		module.teleportPlayer(v, destination)
	end
	return true
end

module.chooseMap = function()
	--choose a map
	local mapFolder = replicatedStorage:FindFirstChild("Maps")
	local maps = mapFolder:GetChildren()
	local numberOfMaps = #maps
	
	local randomNumber = math.random(1, numberOfMaps)
	
	local chosenMap = maps[randomNumber]
	
	if chosenMap then
		--clone in the new map
		local newMap = chosenMap:Clone()
		newMap.Name = "CurrentMap"
		newMap.Parent = workspace
	end
	return true
end

module.cleanUpRound = function()
	--destroy old map
	if workspace:FindFirstChild("CurrentMap") then
		workspace.CurrentMap:Destroy()
	end
	
	--respawn all players in the map 
	module.resetPlayers()
	
	--[[]]
	
	for _, v in pairs(playersInRound) do
		print(v)
	end
	
	playersInRound = {}
	workspace.Zombies:ClearAllChildren()
	return true
end


--remove player from the table if they died
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			if table.find(playersInRound, player.Name) then
				table.remove(playersInRound, table.find(playersInRound, player.Name))
			end
		end)
	end)
end)

return module

Thanks in advance

You never show the code where you use the spawnZombie function, so we can’t really help you in your case. Show everything that leads to your problem (so any scripts that use the function, and any scripts that use the script that uses the function, etc.).

I did, the function is used in the RoundTime function of the module