✓ Accepted answer
Alien = game.ReplicatedStorage.Alien
AlienLimit= 10
AlienCount = 1
Alienfolder = Instance.new("Folder", game.Workspace)
Alienfolder.Name = "Aliens"
while true do
wait(.1)
for i = AlienCount, AlienLimit do
Alienclone = Alien:Clone()
Alienclone.Parent = Alienfolder
AlienCount = AlienCount + 1
Alienclone.Humanoid.Died:Connect(function()
AlienCount = AlienCount - 1
end)
end
end
Tested and works. If you place this script in workspace, and the alien model in ReplicatedStorage, it will spawn 10 zombies. For each one that dies one more will spawn.
Change 'AlienLimit = 10' to whatever number you want as the limit.
Edit:
Didn't consider that you may have spawn locations for the zombies. Or may want to control where they spawn. If so, use this script.
Alien = script.Parent.Alien
Alien.Parent = game.ReplicatedStorage
AlienLimit= 10
AlienCount = 1
Alienfolder = Instance.new("Folder", game.Workspace)
Alienfolder.Name = "Aliens"
while true do
wait(.1)
for i = AlienCount, AlienLimit do
Alienclone = Alien:Clone()
Alienclone.Parent = Alienfolder
AlienCount = AlienCount + 1
Alienclone.Humanoid.Died:Connect(function()
AlienCount = AlienCount - 1
end)
end
end
If you use the second script, create a brick and put the script inside of it. Put the alien model inside of the brick, and place it ontop of the brick.
Edit2:
Updated code to spawn 1 at a time.
Alien = script.Parent.Alien
Alien.Parent = game.ReplicatedStorage
AlienLimit= 10
AlienCount = 1
Alienfolder = Instance.new("Folder", game.Workspace)
Alienfolder.Name = "Aliens"
while true do
wait(10)
if AlienCount < AlienLimit then
Alienclone = Alien:Clone()
Alienclone.Parent = Alienfolder
AlienCount = AlienCount + 1
print(AlienCount - 1)
end
Alienclone.Humanoid.Died:Connect(function()
AlienCount = AlienCount - 1
print(AlienCount - 1)
end)
end
5 comments
Thank you so much, it works very well!
Not a problem! :)
Wait, it started, waited 80 seconds (time I set for alien spawn) , then it spawns all 10 aliens. If any are killed, it waits 80 seconds again and then spawns the amount that were killed. I would like it to wait 80 seconds, spawn one, wait 80 more seconds then spawn another one, until it reaches 10.
I'm sorry. I corrected my answer with a second edit. I tested that one, and it will spawn 1 at a time aslong as its below max.
Thanks a ton!