-- Переменные для координат спавна крипов local radiantSpawnPoint = Vector3.new(133.165,…
- User
-- Переменные для координат спавна крипов local radiantSpawnPoint = Vector3.new(133.165, 0.5, 47.051) local direSpawnPoint = Vector3.new(-132.107, 0.5, 43.742) local creepsattackrange = 9.5 local radiantModels = {} local direModels = {} local middle = Vector3.new(0,10,0) local pathfindingService = game:GetService("PathfindingService") local targetCreepListDire = {} local targetCreepListRadiant = {}
function startFight(creep, targetCreepList, enemyThron) local distanceToMiddle = (middle - creep.PrimaryPart.Position).Magnitude
local targetCreep while targetCreep == nil and #targetCreepList > 0 do targetCreep = targetCreepList[math.random(1, #targetCreepList)] if targetCreep.Humanoid.Health <= 0 then targetCreep = nil end end if targetCreep ~= nil then local initialPos = middle while creep.Humanoid.Health > 0 and targetCreep.Humanoid.Health > 0 do print(11) -- Проверка расстояния между крипами local distance = (targetCreep.PrimaryPart.Position - creep.PrimaryPart.Position).Magnitude if distance <= creepsattackrange + 2 then print(11) coroutine.wrap(function() local cd = false if cd == false then cd = true targetCreep.Humanoid:TakeDamage(math.random(0,5)) targetCreep.Humanoid.Died:Connect(function() if creep.Name == "RadiantCreep" then for _, enemyCreep in ipairs(targetCreepListRadiant:GetChildren()[math.random(1, #targetCreepList)]) do if (enemyCreep.PrimaryPart.Position - creep.PrimaryPart.Position).Magnitude <= creepsattackrange and enemyCreep.Humanoid.Health > 0 then startFight() break end end elseif creep.Name == "DireCreep" then for _, enemyCreep in ipairs(targetCreepListDire:GetChildren()[math.random(1, #targetCreepList)]) do if (enemyCreep.PrimaryPart.Position - creep.PrimaryPart.Position).Magnitude <= creepsattackrange and enemyCreep.Humanoid.Health > 0 then startFight() break end end end end) wait(0.5) cd = false end end)() creep.Humanoid:MoveTo(targetCreep.PrimaryPart.Position) creep.Humanoid.MoveToFinished:Wait() else -- Если враждебный крип убежал далеко, двигаться к нему local path = pathfindingService:CreatePath() path:ComputeAsync(creep.PrimaryPart.Position, targetCreep.PrimaryPart.Position) local waypoints = path:GetWaypoints() for i = 1, #waypoints do creep.Humanoid:MoveTo(waypoints[i].Position) creep.Humanoid.MoveToFinished:Wait() -- Проверка на расстояние после каждого подхода к враждебному крипу distance = (targetCreep.PrimaryPart.Position - creep.PrimaryPart.Position).Magnitude if distance <= creepsattackrange then return end -- Проверка на удаление от координаты “middle” local distanceToMiddle = (middle - creep.PrimaryPart.Position).Magnitude if distanceToMiddle > 40 then creep.Humanoid:MoveTo(middle) -- Возвращаемся к позиции “middle” creep.Humanoid.MoveToFinished:Wait() return end end end end -- Возвращаемся к начальной позиции перед завершением creep.Humanoid:MoveTo(initialPos) creep.Humanoid.MoveToFinished:Wait() else -- Если не найдена цель для атаки из списка creep.Humanoid:MoveTo(enemyThrone.Position) -- Двигаться к вражескому трону creep.Humanoid.MoveToFinished:Wait() end - Assistant
Вот исправленный код, разделённый на два скрипта:
Скрипт "ServerScriptService" (spawnCreepsScript):
local radiantSpawnPoint = Vector3.new(133.165, 0.5, 47.051) local direSpawnPoint = Vector3.new(-132.107, 0.5, 43.742) local radiantModels = {} local direModels = {} local pathfindingService = game:GetService("PathfindingService") local targetCreepListDire = {} local targetCreepListRadiant = {} local modelFolder = game.ServerStorage:WaitForChild("Creeps") -- Получаем список моделей крипов и разделяем их по фракциям for _, model in ipairs(modelFolder:GetChildren()) do if model.Name:find("RadiantCreep") then table.insert(radiantModels, model) elseif model.Name:find("DireCreep") then table.insert(direModels, model) end end local function spawnCreeps() -- Спавн радиантских крипов for _, model in ipairs(radiantModels) do for i = 1, 3 do local creep = model:Clone() creep.Parent = workspace creep.PrimaryPart = creep:FindFirstChild("HumanoidRootPart") creep:SetPrimaryPartCFrame(CFrame.new(radiantSpawnPoint + Vector3.new(i * math.random(2,4), 0, i * math.random(2,4)))) end end -- Спавн дирских крипов for _, model in ipairs(direModels) do for i = 1, 3 do local creep = model:Clone() creep.Parent = workspace creep.PrimaryPart = creep:FindFirstChild("HumanoidRootPart") creep:SetPrimaryPartCFrame(CFrame.new(direSpawnPoint + Vector3.new(i * math.random(2,4), 0, i * math.random(2,4)))) end end end spawnCreeps()