[solved] Multiple Zombies Do Not Spawn at Once

For my game, after a certain amount of seconds, I want zombies to spawn. Some zombies have a higher chance of spawning than others. Each zombie can spawn more than once, like you could have 5 normal zombies and 3 fast zombies, etc… The problem is, only one of the zombies from that type of zombie can spawn.

Script for picking zombies/teleporting them:

local Items = {
	{"Zomb", 4},
	{"Skinny Zomb", 2.5},
	{"Crawl Zomb", 3},
	{"Football Zomb", 2.5},
	{"Regen Zomb", 2},
	{"Small Zomb", 2},
	{"Big Zomb", 1},
	{"Fast Zomb", 3},
}

local spawnpart = game.Workspace.spawnpart
local zombfolder = game.ServerStorage.storedzombies:GetChildren()
local InRound = game.ReplicatedStorage.InRound

local multiplier = 1

for _, item in pairs(Items) do 
	local function zeros(amount)
		local total = "1"
		for i = 1, amount do
			total = total.. "0"
		end
		return total
	end
	local split = string.split(tostring(item[2]), ".")
	if split[2] ~= nil then
		if tonumber(zeros(string.len(split[2]))) > multiplier then
			multiplier = tonumber(zeros(string.len(split[2])))
		end
	end
end
print(multiplier)
for _, item in pairs(Items) do
	item[2] = item[2] * multiplier
end

local TotalWeight = 0

for _,ItemData in pairs(Items) do
	TotalWeight = TotalWeight + ItemData[2]
end

local function chooseRandomItem()
	local Chance = math.random(1,TotalWeight)
	local Counter = 0
	for _,ItemData in pairs(Items) do
		Counter = Counter + ItemData[2]
		if Chance <= Counter then
			return ItemData[1]
		end
	end
end


InRound.Changed:Connect(function() --happens when intermission timer runs out and zombies come
	if InRound.Value == true then 
		local range = 10

for i = 1, 30 do -- i want 30 to spawn
	for i,v in pairs(zombfolder) do
		if chooseRandomItem() == v.Name then
			print(chooseRandomItem()) -- 30 random ones are printed but not cloned
			v:Clone()
			v.Parent = game.Workspace.zombies
					v.PrimaryPart.Position = spawnpart.Position + Vector3.new(math.random(-range,range),math.random(-range,range),math.random(-range,range))
		end
	end
end

end
end)
1 Like

Seems like the humanoid property “HipHeight” is too low. Try increasing it a bit and see if it makes any difference.

1 Like

Actually I just fixed that issue by using CFrame instead of Position. I just need to try to fix how many of them actually spawn now. Thanks for the reply

1 Like

nevermind I fixed it all, i made a foolish mistake

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.