RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"spread the spawnedNPCs evenly across the available spawns"
-- roblox script local wave = 1 local maxWaves = 25 local spawns = {game.Workspace.NPCSpawn1, game.Workspace.NPCSpawn2, game.Workspace.NPCSpawn3} local npcs = game.ReplicatedStorage.NPCs:GetChildren() while wave <= maxWaves do local spawnCount if wave == 1 then spawnCount = 5 elseif wave < 4 then spawnCount = math.floor(5 * (1.25^(wave - 1))) else spawnCount = math.floor(5 * (1.5^(wave - 1))) end local spawnedNPCs = {} for i = 1, spawnCount do local npc = npcs[math.random(#npcs)]:Clone() local spawn = spawns[(i - 1) % #spawns + 1] npc.Parent = game.Workspace npc.HumanoidRootPart.CFrame = spawn.CFrame table.insert(spawnedNPCs, npc) end -- wait until all NPCs have died before starting next wave while #spawnedNPCs > 0 do for i, npc in ipairs(spawnedNPCs) do if npc.Humanoid.Health <= 0 then table.remove(spawnedNPCs, i) end end task.wait(1) end wave = wave + 1 end