Im making a “dungeon” gamemode where enemys spawn in waves and get progressively stronger has it goes on, ive gotten my wave system down my problem lies in making boss waves about every 10 waves. Heres my script so far:
local collectService = game:GetService("CollectionService")
local Mobs = {[1] = script:WaitForChild("Marine")}
local BossMobs = {[10] = script:WaitForChild("IceMarine"), [20] = script:WaitForChild("LightMarine"), [30] = script:WaitForChild('MagmaMarine')}
local mobSpawns = game.Workspace.MobSpawns
local StatusValue = game.ReplicatedStorage.StatusValue
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://3424356768"
sound.Looped = false
local respawnWave = 1
local StartingMobs = 5
local lastHealth = 75
local maxWave = 30
local canrespawn = false
local WaveSound = game.ReplicatedStorage.DungeonSFX.Wave
local mobsToSpawn = (StartingMobs)
while true do
StatusValue.Value = "Wave Starting"
for i, child in pairs(workspace:WaitForChild("Monster"):GetChildren()) do
collectService:RemoveTag(child, "mob")
end
workspace.Monster:ClearAllChildren()
wait(5)
local aliveplrs = {}
for i,plr in pairs(game.Players:GetChildren()) do
plr:LoadCharacter()
table.insert(aliveplrs, plr)
if #aliveplrs > 1 then
canrespawn = true
end
plr.Character.Humanoid.Died:Connect(function()
table.remove(aliveplrs, aliveplrs[plr])
end)
end
for i = 1, maxWave do
local addmobs = mobsToSpawn + 5
StatusValue.Value = "Wave " ..i.. " starting."
wait(15)
sound:Play()
local mobTypeSpawn
if i ~= 1 or i ~= 20 or i ~= 30 then
for wavenum,mobtype in pairs(Mobs) do
if i >= wavenum then
mobTypeSpawn = mobtype
break
end
end
elseif i == 1 then
warn("BPSSSSS")
mobsToSpawn = 1
mobTypeSpawn = script:WaitForChild("IceMarine")
elseif i == 20 then
mobsToSpawn = 1
mobTypeSpawn = script:WaitForChild("LightMarine")
elseif i == 30 then
mobsToSpawn = 1
mobTypeSpawn = script:WaitForChild("MagmaMarine")
end
while mobsToSpawn > 0 do
for x, spawner in pairs(mobSpawns:GetChildren()) do
mobsToSpawn -= 1
local mobClone = mobTypeSpawn:Clone()
mobClone.HumanoidRootPart.CFrame = spawner.CFrame + Vector3.new(0,10,0)
mobClone.Humanoid.MaxHealth = lastHealth
mobClone.Humanoid.Health = lastHealth
mobClone.Humanoid.WalkSpeed = 16
mobClone.Humanoid.HipHeight = 2.657
mobClone.Humanoid.MaxSlopeAngle = 89
collectService:AddTag(mobClone, "mob")
mobClone.Humanoid.Died:Connect(function()
collectService:RemoveTag(mobClone, "mob")
mobClone:Destroy()
end)
local NewHealth = lastHealth + 100
lastHealth = NewHealth
print()
mobClone.Parent = workspace:WaitForChild("Monster")
end
end
mobsToSpawn = addmobs
local valuetoshow = #workspace:WaitForChild("Monster"):GetChildren()
repeat
wait()
StatusValue.Value = "Wave " .. i .. " | " .. #workspace:WaitForChild("Monster"):GetChildren() .. "/" .. valuetoshow .. "Enemys"
until #workspace:WaitForChild("Monster"):GetChildren() < 1 or #aliveplrs < 1
Players = game:GetService("Players")
local playersToteleport = {}
for i, player in pairs(Players:GetPlayers()) do
table.insert(playersToteleport, player)
end
if #aliveplrs < 1 then
print("tleleprotr")
local teleportService = game:GetService("TeleportService")
teleportService:TeleportAsync(8123652942, playersToteleport)
break
end
if i % respawnWave == 0 then
for z, plr in pairs(game.Players:GetPlayers()) do
if not plr.Character then
plr:LoadCharacter()
table.insert(aliveplrs, plr)
end
end
end
end
end
this snippet of code is where i tried making my boss waves but currently its not working.
if i ~= 1 or i ~= 20 or i ~= 30 then
for wavenum,mobtype in pairs(Mobs) do
if i >= wavenum then
mobTypeSpawn = mobtype
break
end
end
elseif i == 1 then
warn("BPSSSSS")
mobsToSpawn = 1
mobTypeSpawn = script:WaitForChild("IceMarine")
elseif i == 20 then
mobsToSpawn = 1
mobTypeSpawn = script:WaitForChild("LightMarine")
elseif i == 30 then
mobsToSpawn = 1
mobTypeSpawn = script:WaitForChild("MagmaMarine")
end
thank you for reading if you need further information please ask.