local pathfindingService = game:GetService("PathfindingService") local creepsattackrange…
- User
local pathfindingService = game:GetService("PathfindingService") local creepsattackrange = 4 local targetCreepListDire = {} local targetCreepListRadiant = {}
local function startFight(creep, targetCreepList, enemyThrone, creepsattackrange) local path = pathfindingService:FindPathAsync(creep.HumanoidRootPart.Position, enemyThrone.Position) -- Найти путь до трона противоположной фракции if path.Status == Enum.PathStatus.Success then local waypoints = path:GetWaypoints() for i, waypoint in ipairs(waypoints) do -- Перемещение крипа по пути creep.Humanoid:MoveTo(waypoint.Position) -- Драться с крипами противоположной фракции, если они встречены for _, targetCreep in ipairs(targetCreepList) do if (targetCreep.HumanoidRootPart.Position - creep.HumanoidRootPart.Position).magnitude <= creepsattackrange then -- начать сражение end end end end end
wait(0.1) for i, enemyCreep in pairs(game.Workspace:GetChildren()) do if enemyCreep.Name == "DireCreep" then table.insert(targetCreepListRadiant, enemyCreep) elseif enemyCreep.Name == "RadiantCreep" then table.insert(targetCreepListDire, enemyCreep) end end
if script.Parent.Name == "DireCreep" then for _, creep in ipairs(targetCreepListDire) do startFight(script.Parent, targetCreepListDire, game.Workspace.RadiantAncient, creepsattackrange) end elseif script.Parent.Name == "RadiantCreep" then for _, creep in ipairs(targetCreepListRadiant) do startFight(script.Parent, targetCreepListRadiant, game.Workspace.DireAncient, creepsattackrange) end end крипы не обходят препятствия, может нужен цикл?
- Assistant