[SERVER]:local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UnitsRequest = ReplicatedStorage.Functions.UnitsRequest
local unitModule = require(ReplicatedStorage.Modules.BossModules.Unit)
local BossesFolder = ReplicatedStorage.Bosses
local map = workspace.Map
local boss = {}
function boss.Start(player,bossName)
print("Boss started")
local bossToClone = BossesFolder:FindFirstChild(bossName)
if bossToClone then
local bossToSpawn = bossToClone:Clone()
bossToSpawn.Parent = map.Mobs
--bossToSpawn.Owner.Value = player.Name
bossToSpawn.HumanoidRootPart.CFrame = map.BossSpawn.CFrame * CFrame.new(0,5,0)
bossToSpawn.Humanoid.Died:Connect(function()
player.Character.HumanoidRootPart.CFrame = workspace.SpawnLocation.CFrame
end)
local success, canStart, Units = pcall(function()
return UnitsRequest:InvokeClient(player)
end)
if not success or not canStart or not Units then
warn("Units request failed for player: ".. player.Name)
return
end
for _, unit in ipairs(Units) do
print(unit.Name)
local unitClone = ReplicatedStorage.Noobs:FindFirstChild(unit.Name)
if unitClone then
local clone:Model = unitClone:Clone()
clone.Parent = map.Units
local spawnOBJ = map.TowerSpawns:GetChildren()[math.random(1,#map.TowerSpawns:GetChildren())]
clone.PrimaryPart.CFrame = spawnOBJ.CFrame + Vector3.new(0,5,0)
clone:ScaleTo(0.3)
clone.Humanoid.Died:Connect(function()
clone:Destroy()
unit:Destroy()
end)
unitModule.Start(clone,bossToSpawn)
end
end
else
warn("Boss: " .. boss .." Doesn't exist")
end
end
return boss
