So recently I’m trying to make a wave system. But I am facing an issue. The problem is
I want 2 type of mobs spawns on wave 3 but it only spawn 1 type of mobs
local MPS = game:GetService("MarketplaceService")
local CS = game:GetService("CollectionService")
local TeleportService = game:GetService("TeleportService")
local data = {}
game.Players.PlayerAdded:Connect(function(player)
local Ls = Instance.new("Folder")
Ls.Parent = player
Ls.Name = "leaderstats"
local cash = Instance.new("IntValue")
cash.Parent = Ls
cash.Name = "Cash"
cash.Value = 0
local Wins = Instance.new("NumberValue")
Wins.Parent = Ls
Wins.Value = 0
Wins.Name = "Wins"
end)
local MobSpawns = game.Workspace:WaitForChild("MobSpawns")
local status = game.ReplicatedStorage:WaitForChild("StatusValue")
local NarratorValue = game.ReplicatedStorage:WaitForChild("NarrationText")
local BaconsCounter = game.ReplicatedStorage:WaitForChild("BaconCounter")
local MobsFolder = game.Workspace:WaitForChild("MobsFolder")
local mobs = {
[3] = {script:WaitForChild("Bacon"), script:WaitForChild("BreakfastBacon")}, [2] = script:WaitForChild("BreakfastBacon"), [1] = script:WaitForChild("Bacon")
}
print(mobs[3])
print({mobs})
local respawnWave = 10
local startingMobs = 1
local maxWave = 15
local AlivePlrs = {}
for _, child in pairs(MobsFolder:GetChildren()) do
CS:RemoveTag(child, "mob")
end
MobsFolder:ClearAllChildren()
local function NarratorText(Text)
for i = 1, #Text, 1 do
NarratorValue.Value = string.sub(Text, 1, i)
task.wait(.05)
end
end
for timer = 1, 0, -1 do
task.wait(1)
status.Value = "Waiting..." .. timer
end
game.ReplicatedStorage.NarratorGUIRE:FireAllClients(1)
NarratorText("Greetings player...")
task.wait(1.5)
NarratorText("Bacons will be swarming you soon. Get your defences ready!")
for _, player in pairs(game.Players:GetPlayers()) do
local character = player.Character
table.insert(AlivePlrs, player)
player.Character.Humanoid.Died:Connect(function()
table.remove(AlivePlrs, AlivePlrs[player])
end)
if MPS:UserOwnsGamePassAsync(player.UserId, 28234390) then
player.Backpack:ClearAllChildren()
local sword = game.ReplicatedStorage:WaitForChild("2xDmgSword"):Clone()
sword.Parent = player.Backpack
end
end
for i = 1, maxWave do
for _, player in pairs(AlivePlrs) do
if player then
player.Character.Humanoid.Health = player.Character.Humanoid.MaxHealth
end
end
local AirDrop = game.ServerStorage:WaitForChild("AirDrop"):Clone()
local RandomSpawns = game.Workspace.AirDropArea:GetChildren()
AirDrop.Parent = game.Workspace
AirDrop.PrimaryPart.CFrame = RandomSpawns[math.random(1, #RandomSpawns)].CFrame + Vector3.new(0,40,0)
local mobsSpawn = 1
status.Value = "Wave "..i
task.wait(2)
local MobTypeSpawn
for waveNum, mobType in pairs(mobs) do
if i >= waveNum then
MobTypeSpawn = mobType
end
end
while mobsSpawn > 0 do
local RandomizeSpawns = MobSpawns:GetChildren()
local randomSpawnsForWaves = RandomizeSpawns[math.random(1,#RandomizeSpawns)]
if i == 3 then
local MobToCloneWave3 = MobTypeSpawn:Clone()
local spawnerWave3 = randomSpawnsForWaves:Clone()
spawnerWave3.Name = "Part"
spawnerWave3.Parent = MobSpawns
elseif i == 5 then
local spawnerWave5 = randomSpawnsForWaves:Clone()
spawnerWave5.Name = "Part"
spawnerWave5.Parent = MobSpawns
local spawnerWave52 = randomSpawnsForWaves:Clone()
spawnerWave52.Name = "Part"
spawnerWave52.Parent = MobSpawns
elseif i == 10 then
game.ReplicatedStorage.NarratorGUIRE:FireAllClients(10)
NarratorText("Uh oh, more bacons incoming... Becareful!")
task.wait(.1)
local spawner1 = randomSpawnsForWaves:Clone()
spawner1.Name = "Part"
spawner1.Parent = MobSpawns
local spawner2 = randomSpawnsForWaves:Clone()
spawner2.Name = "Part"
spawner2.Parent = MobSpawns
local spawner3 = randomSpawnsForWaves:Clone()
spawner3.Name = "Part"
spawner3.Parent = MobSpawns
elseif i == 12 then
local spawner2 = randomSpawnsForWaves:Clone()
spawner2.Name = "Part"
spawner2.Parent = MobSpawns
local spawner3 = randomSpawnsForWaves:Clone()
spawner3.Name = "Part"
spawner3.Parent = MobSpawns
elseif i == 15 then
local spawner2 = randomSpawnsForWaves:Clone()
spawner2.Name = "Part"
spawner2.Parent = MobSpawns
local spawner3 = randomSpawnsForWaves:Clone()
spawner3.Name = "Part"
spawner3.Parent = MobSpawns
local spawner2 = randomSpawnsForWaves:Clone()
spawner2.Name = "Part"
spawner2.Parent = MobSpawns
end
for x, spawner in pairs(MobSpawns:GetChildren()) do
mobsSpawn -= 1
local MobToClone = MobTypeSpawn:Clone()
MobToClone:SetPrimaryPartCFrame(spawner.CFrame) --= spawner.CFrame + Vector3.new(0,10,0)
CS:AddTag(MobToClone, "mob")
MobToClone.Humanoid.Died:Connect(function()
CS:RemoveTag(MobToClone, "mob")
MobToClone:Destroy()
end)
MobToClone.Parent = game.Workspace:WaitForChild("MobsFolder")
end
end
repeat
task.wait()
BaconsCounter.Value = #workspace:WaitForChild("MobsFolder"):GetChildren() .. "/" .. #workspace:WaitForChild("MobSpawns"):GetChildren()
until #MobsFolder:GetChildren() < 1 or #AlivePlrs < 1
if #MobsFolder:GetChildren() < 1 then
BaconsCounter.Value = "Survived Wave " .. i
game.Workspace:FindFirstChild("AirDrop"):Destroy()
end
if i == 14 then
local BossBacon = script:WaitForChild("BossBacon"):Clone()
game.ReplicatedStorage.NarratorGUIRE:FireAllClients(15)
NarratorText("The Bacon boss and his army has arrived! Use your swords and slash them into half.")
task.wait(.1)
BossBacon.Parent = game.Workspace:WaitForChild("MobsFolder")
BossBacon:SetPrimaryPartCFrame(game.Workspace.SpawnerBoss.CFrame)-- = game.Workspace.SpawnerBoss.CFrame + Vector3.new(0,10,0)
BossBacon.Humanoid.WalkSpeed = BossBacon.Settings.Speed.Value
BossBacon.Humanoid.MaxHealth = BossBacon.Settings.Health.Value
BossBacon.Humanoid.Health = BossBacon.Humanoid.MaxHealth
CS:AddTag(BossBacon, "mob")
BossBacon.Humanoid.Died:Connect(function()
CS:RemoveTag(BossBacon, "mob")
BossBacon:Destroy()
end)
end
if i == maxWave and #MobsFolder:GetChildren() < 1 then
status.Value = "Victory!... (TELEPORTING PLAYERS)"
for _, player in pairs(game.Players:GetPlayers()) do
for _, aliveplr in pairs(AlivePlrs) do
if #game.Players:GetPlayers() == 2 then
player.leaderstats.Wins.Value += 1
elseif #game.Players:GetPlayers() == 1 then
aliveplr.leaderstats.Wins.Value += 1
end
end
data["Wins"] = player.leaderstats.Wins.Value
data["Coins"] = player.leaderstats.Cash.Value
TeleportService:Teleport(8597947999, player, data)
end
end
if #AlivePlrs < 1 then
status.Value = "Game Ended, All players died (Teleporting)"
game.Workspace.MobsFolder:ClearAllChildren()
for _, player in pairs(game.Players:GetPlayers()) do
data["Wins"] = player.leaderstats.Wins.Value
data["Coins"] = player.leaderstats.Cash.Value
TeleportService:Teleport(8597947999, player, data)
end
else
for _, playerAlive in pairs(AlivePlrs) do
playerAlive.leaderstats.Cash.Value += (5 * i)
end
if i % respawnWave == 0 then
for _, plrs in pairs(game.Players:GetPlayers()) do
if not plrs.Character then
plrs:LoadCharacter()
if MPS:UserOwnsGamePassAsync(plrs.UserId, 28234390) then
plrs.Backpack:ClearAllChildren()
local sword = game.ReplicatedStorage:WaitForChild("2xDmgSword"):Clone()
sword.Parent = plrs.Backpack
end
end
end
end
end
end
local mobs = {
[3] = {script:WaitForChild("Bacon"), script:WaitForChild("BreakfastBacon")}, [2] = script:WaitForChild("BreakfastBacon"), [1] = script:WaitForChild("Bacon")
}
the [3] table is the table that i want 2 type mobs spawns but it only spawns 1 type of mob