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

Zombie spawner doesn't work as intended, why?

Ok, so I've ran into a little bit of a problem, I'm making a zombie spawner script and the zombies do spawn, but instead of spawning in all the possible spawn locations (which are invisible Parts) they all spawn in the same one

This is the spawn function:

function Commands.SpawnZombie(amount, class, safeMode)
	local zombieType = game.ReplicatedStorage.Zombies[class]

	for i = 1, amount do 
		if safeMode == true then
			if game.ReplicatedStorage.ServerDetails.RoundActive == false then
				return
			end
		end

		local zombie = zombieType:Clone()
		zombie.Parent = game.Workspace.NPCs
		
		local RandomSpawnLocation = GetRandomSpawnLocation()

		zombie.PrimaryPart.CFrame = RandomSpawnLocation.CFrame
	end
end

And this is the GetRandomSpawnLocation() function:

function GetRandomSpawnLocation()
	local SpawnZones = game.Workspace.Map.SpawnZones:GetChildren()
	local randomSpawnZone = SpawnZones[math.random(1, #SpawnZones)]

	local SpawnLocations = randomSpawnZone:GetChildren()
	local RandomSpawnLocation = SpawnLocations[math.random(1, #SpawnLocations)]

	return RandomSpawnLocation
end

A bit of information: The GetRandomSpawnLocation basically gets a random SpawnZone (which is a big part with alot of small parts inside it) then it gets a random SpawnLocation which are one of the small parts, and returns that location

But as i said, even tho im firing the function every loop, it still spawns them in the same place. why does this happen? please help :c

10 comments

0

..

0

Also forgot to mention try putting the pads in a folder and name it SpawnPad if that doesn't work name it to ZombieSpawns

0

Rename folder to**

0

Also can you maybe give me a screenshot? Upload your screenshot as a decal on Roblox and give me the link.

0
0

I added a screenshot on your answer, it's from the Lightshot app

0

Have you tried using break points and call stack to debug? Or maybe printing the tables?

0

Sorry, I don't know what break points and call stack are, I can try printing the table tho

0

Nothing, it's printing what it's supposed to print, the table of spawnpads, Idk what to do anymore lol, is there any chance that it being a ModuleScript is making it break? because the spawn function is fired from another script, calling the Spawn Module Script

0

probably try normal script

1 answer

Maybe try the math random pads like this Example:

local pads = game.Workspace.ZombieSpawns

	local SpawnPad = pads:FindFirstChild("Pad"..math.random(1,#pads:GetChildren()))

	NewestPad:SetPrimaryPartCFrame(SpawnPad.CFrame + Vector3.new(0,3,0))

	wait()

	NewestPad.Parent = workspace

You might need to edit it to your set up Hope this helps!!

15 comments

0

Also is there any errors

0

Hey king, no, there is not any errors when I run my script, and when I use yours there is no errors either, but i checked and SpawnPad is equal to nil, I even changed "Pad" to the name of the part but still, doesn't work, plus every spawn part has a different name so having to enter it's name wont make it random, what could i do?

0

Here is a picture If you'd like to see what happens: https://prnt.sc/lGzGRClA6Y5x

0

You should have the spawnpads as named pad1. Make sure you keep upping the number by 1

0

Also might need to customize the code in this code block to work with your system

0

Mhm, I did customize it, and the "pads" are all called "Spawner1, Spawner2, Spawner3" etc..., I'll try it again

0

OK make sure you rename pads then in script

0

It didn't work, this is killing my brain nothing seems to work and I don't know why

0

mmmmm

0

this is the last thing i can suggest

0

Have you tried putting the spawnpads in a folder and naming the folder Spawnpad? Also try not having it in a folder unless if you already did tried that.

0

Yea i did try that, but i'll try it again

0

No, goddd, it doesn't work, I truly don't get why if im firing the GetRandomSpawnLocation() function 3 times, it chooses the same one for the 3 zombies.

0

Very weird

0

I have to think of more ideas

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