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

Spawning Once? Zombie Spawner

Zombie Spawner I made, very basic. Although it only spawns one zombie. It never says "spawned" in the output except for the one time it spawns. I was wondering if anyone knows why this is happening? It is supposed to spawn one every second until there are 30. Any help is appreciated :)

local z = game.ReplicatedStorage.Zombie
local zc = z:Clone()
local fm = game.Workspace:FindFirstChild("Map")
local fs = fm:GetChildren("ZSpawn")


while true do
	wait(10)
		if fm then
				for i = 1,1,30 do
			zc.Parent = game.Workspace
			zc.Position = fs.Position
		print("Spawned")
		end
	end
end

2 answers

You're chasing your tail the wrong way.

The for loop goes (init, lim, inc)

local z = game.ReplicatedStorage.Zombie
local zc = z:Clone()
local fm = game.Workspace:FindFirstChild("Map")
local fs = fm:GetChildren("ZSpawn")


while true do
    wait(10)
        if fm then
                for i = 1,30,1 do
            zc.Parent = game.Workspace
            zc.Position = fs.Position
        print("Spawned")
        end
    end
end

The script will now make you chase your tail 30 times, and that will make you spawn zombies 30 times.


woof woof

For your for loop, you've set the starting number as 1, the ending number as 1 and the increment as 30.

Obviously that won't work, so I'd recommend trying the following script:

local z = game.ReplicatedStorage.Zombie
local zc = z:Clone()
local fm = game.Workspace:FindFirstChild("Map")
local fs = fm:GetChildren("ZSpawn")


while true do
    wait(10)
        if fm then
                for i = 1,30,1 do --Although the increment is 1 by default, so it's not essential
            zc.Parent = game.Workspace
            zc.Position = fs.Position
        print("Spawned")
        end
    end
end

Here's a webpage which you might find useful

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