function startFight(creep, enemyThrone, targetCreepList) local distanceToMiddle =…
- User
function startFight(creep, enemyThrone, targetCreepList) local distanceToMiddle = (middle - creep.PrimaryPart.Position).Magnitude
codelocal 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)) 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
It seems that the error is occurring on line 14 of the script. The error message suggests that you are trying to get the length of an Instance value, which is not allowed.
Looking at the code, the issue may be with the variable
targetCreepList. It appears to be an Instance value, but the code is treating it as a table. To fix this, you need to convert thetargetCreepListinto a table by iterating over the Instance and adding each element to the table.Here's an updated version of the code that should fix the error:
luafunction startFight(creep, enemyThrone, targetCreepList) local targetCreepTable = {} for _, targetCreep in ipairs(targetCreepList:GetChildren()) do if targetCreep.Humanoid.Health > 0 then table.insert(targetCreepTable, targetCreep) end end local distanceToMiddle = (middle - creep.PrimaryPart.Position).Magnitude local targetCreep while targetCreep == nil and #targetCreepTable > 0 do targetCreep = targetCreepTable[math.random(1, #targetCreepTable)] if targetCreep.Humanoid.Health <= 0 then targetCreep = nil end end -- rest of the code end