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() local index = 1 while index <= #waypoints do creep.Humanoid:MoveTo(waypoints[index].Position)
codelocal currentWaypoint = waypoints[index] local nextWaypoint = waypoints[index + 1] -- Проверяем, достигли ли крипы следующей точки пути if nextWaypoint and (creep.HumanoidRootPart.Position - nextWaypoint.Position).magnitude <= 2 then index = index + 1 end -- Драться с крипами противоположной фракции, если они встречены for _, targetCreep in ipairs(targetCreepList) do if (targetCreep.HumanoidRootPart.Position - creep.HumanoidRootPart.Position).magnitude <= creepsattackrange then -- начать сражение end end wait(0.1) end endend
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
Текущая проблема в том, что вы запускаете функцию
startFightтолько один раз для каждого крипа, вместо того чтобы повторять ее в цикле, чтобы крипы продолжали двигаться вперед.Вот исправленный код: