Hello, I’m working on a monster spawn system that currently spawns a new monster every 30 seconds. I want to implement a check for if there are more than 5 monsters currently alive no more can spawn.
My current script:
while true do
local monster = game:GetService("ServerStorage"):WaitForChild("Monster"):Clone()
monster.Parent = workspace
monster:MoveTo(game.Workspace.MonsterSpawn.Position)
wait(30)
end
have you considered placing monster models inside a separate folder inside of workspace? you would be able to do something like
local MonsterFolder = instance.new("folder")
MonsterFolder.Parent = workspace
while #workspace.MonsterFolder:getChildren() < 5 do
local monster = game:GetService("ServerStorage"):WaitForChild("Monster"):Clone()
monster.Parent = workspace.MonsterFolder
monster:MoveTo(game.Workspace.MonsterSpawn.Position)
wait(30)
end
Ok, so the script works, I just have one problem, once all of the monsters are killed no more spawn. How do I clear up the folder once all of the monsters are dead so more can spawn?