\local db = false -- Personal creep stats -- local slashanim = script.slashanim local…
- User
\local db = false
-- Personal creep stats --
local slashanim = script.slashanim local atkspeed = 70/65 local dps = math.random(19, 23)
local pathfindingService = game:GetService("PathfindingService") local creepsattackrange = 25 local targetCreepListDire = {} local targetCreepListRadiant = {} local waypoints = {} local dfws = 325 / 25 local fighting = false script.Parent:WaitForChild("Humanoid") script.Parent:WaitForChild("HumanoidRootPart") script.Parent:WaitForChild("Humanoid").WalkSpeed = dfws script:WaitForChild("ReachedPos")
local function attackCreep(creep, enemycreep) if enemycreep.Humanoid.Health > 0 and creep.Humanoid.Health > 0 then fighting = true waypoints = {} creep.Humanoid:MoveTo(enemycreep.HumanoidRootPart.Position) if (creep.HumanoidRootPart.Position - enemycreep.HumanoidRootPart.Position).Magnitude <= 3.5 then creep.Humanoid.WalkSpeed = dfws / 2.5 if db == false then db = true creep.Head.Slash:Play() if slashanim.Value == 1 then creep.Humanoid:LoadAnimation(script.Slash1):Play() slashanim.Value = 2 elseif slashanim.Value == 2 then creep.Humanoid:LoadAnimation(script.Slash2):Play() slashanim.Value = 1 end if math.random(0,enemycreep.MissChance.Value) <= enemycreep.MissChance.Value / 25 then if enemycreep:FindFirstChild("invincibility").Value == false then enemycreep.Humanoid:TakeDamage(dps) end wait(atkspeed) db = false end end else creep.Humanoid.WalkSpeed = dfws end if enemycreep.Humanoid.Health <= 0 then for i, v in pairs(creep.Humanoid.Animator:GetPlayingAnimationTracks()) do if v.Name == "Slash1" or v.Name == "Slash2" then v:Stop() end end creep.Humanoid.WalkSpeed = dfws local cs = script.Parent:Clone() cs.Parent = script.Parent.Parent script:Destroy() end else for i, v in pairs(creep.Humanoid.Animator:GetPlayingAnimationTracks()) do if v.Name == "Slash1" or v.Name == "Slash2" then v:Stop() end end creep.Humanoid.WalkSpeed = dfws local cs = script.Parent:Clone() cs.Parent = script.Parent.Parent script:Destroy() end end
local function attackTower(creep, tower) if tower.Faction.Value ~= creep.Faction.Value then if tower.Health.Value > 0 and creep.Humanoid.Health > 0 then fighting = true waypoints = {} creep.Humanoid:MoveTo(tower.BasePart.Position) if (creep.HumanoidRootPart.Position - tower.BasePart.Position).Magnitude <= 7 then creep.Humanoid.WalkSpeed = dfws / 2.5 if db == false then db = true creep.Head.Slash:Play() if slashanim.Value == 1 then creep.Humanoid:LoadAnimation(script.Slash1):Play() slashanim.Value = 2 elseif slashanim.Value == 2 then creep.Humanoid:LoadAnimation(script.Slash2):Play() slashanim.Value = 1 end if tower:FindFirstChild("invincibility").Value == false then tower.Health.Value = tower.Health.Value - (dps / 1.2) end wait(atkspeed) db = false end
else creep.Humanoid.WalkSpeed = dfws end if tower.Health.Value <= 0 then for i, v in pairs(creep.Humanoid.Animator:GetPlayingAnimationTracks()) do if v.Name == "Slash1" or v.Name == "Slash2" then v:Stop() end end creep.Humanoid.WalkSpeed = dfws local cs = script.Parent:Clone() cs.Parent = script.Parent.Parent script:Destroy() end else return end endend
local function Lane(creep, targetCreepList, enemyThrone, enemyTowers) while creep.Humanoid.Health > 0 and fighting == false do if fighting == false then if creep.Faction.Value == "Radiant" then if script.ReachedPos.Value == 0 then creep.Humanoid.WalkSpeed = dfws local path = pathfindingService:CreatePath() path:ComputeAsync(creep.PrimaryPart.Position, game.Workspace.Top2.Position)
waypoints = path:GetWaypoints() for i, waypoint in ipairs(waypoints) do creep.Humanoid:MoveTo(waypoint.Position) creep.Humanoid.MoveToFinished:Wait() end if (creep.PrimaryPart.Position - game.Workspace.Top2.Position).Magnitude <= 10 then script.ReachedPos.Value = 1 for i, v in pairs(creep.Humanoid.Animator:GetPlayingAnimationTracks()) do if v.Name == "Slash1" or v.Name == "Slash2" then v:Stop() end end creep.Humanoid.WalkSpeed = dfws local cs = script.Parent:Clone() cs.Parent = script.Parent.Parent script:Destroy() end wait() elseif script.ReachedPos.Value == 1 then creep.Humanoid.WalkSpeed = dfws local path = pathfindingService:CreatePath() path:ComputeAsync(creep.PrimaryPart.Position, game.Workspace.Bot2.Position) waypoints = path:GetWaypoints() for i, waypoint in ipairs(waypoints) do creep.Humanoid:MoveTo(waypoint.Position) creep.Humanoid.MoveToFinished:Wait() end if (creep.PrimaryPart.Position - game.Workspace.Bot2.Position).Magnitude <= 10 then script.ReachedPos.Value = 2 for i, v in pairs(creep.Humanoid.Animator:GetPlayingAnimationTracks()) do if v.Name == "Slash1" or v.Name == "Slash2" then v:Stop() end end creep.Humanoid.WalkSpeed = dfws local cs = script.Parent:Clone() cs.Parent = script.Parent.Parent script:Destroy() end wait() elseif script.ReachedPos.Value == 2 then creep.Humanoid.WalkSpeed = dfws local path = pathfindingService:CreatePath() path:ComputeAsync(creep.PrimaryPart.Position, enemyThrone.Position) waypoints = path:GetWaypoints() for i, waypoint in ipairs(waypoints) do creep.Humanoid:MoveTo(waypoint.Position) creep.Humanoid.MoveToFinished:Wait() end wait() end elseif creep.Faction.Value == "Dire" then if script.ReachedPos.Value == 0 then creep.Humanoid.WalkSpeed = dfws local path = pathfindingService:CreatePath() path:ComputeAsync(creep.PrimaryPart.Position, game.Workspace.Bot2.Position) waypoints = path:GetWaypoints() for i, waypoint in ipairs(waypoints) do creep.Humanoid:MoveTo(waypoint.Position) creep.Humanoid.MoveToFinished:Wait() end if (creep.PrimaryPart.Position - game.Workspace.Bot2.Position).Magnitude <= 10 then script.ReachedPos.Value = 1 for i, v in pairs(creep.Humanoid.Animator:GetPlayingAnimationTracks()) do if v.Name == "Slash1" or v.Name == "Slash2" then v:Stop() end end creep.Humanoid.WalkSpeed = dfws local cs = script.Parent:Clone() cs.Parent = script.Parent.Parent script:Destroy() end wait() elseif script.ReachedPos.Value == 1 then creep.Humanoid.WalkSpeed = dfws local path = pathfindingService:CreatePath() path:ComputeAsync(creep.PrimaryPart.Position, game.Workspace.Top1.Position) waypoints = path:GetWaypoints() for i, waypoint in ipairs(waypoints) do creep.Humanoid:MoveTo(waypoint.Position) creep.Humanoid.MoveToFinished:Wait() end if (creep.PrimaryPart.Position - game.Workspace.Top1.Position).Magnitude <= 10 then script.ReachedPos.Value = 2 for i, v in pairs(creep.Humanoid.Animator:GetPlayingAnimationTracks()) do if v.Name == "Slash1" or v.Name == "Slash2" then v:Stop() end end creep.Humanoid.WalkSpeed = dfws local cs = script.Parent:Clone() cs.Parent = script.Parent.Parent script:Destroy() end wait() elseif script.ReachedPos.Value == 2 then creep.Humanoid.WalkSpeed = dfws local path = pathfindingService:CreatePath() path:ComputeAsync(creep.PrimaryPart.Position, enemyThrone.Position) waypoints = path:GetWaypoints() for i, waypoint in ipairs(waypoints) do creep.Humanoid:MoveTo(waypoint.Position) creep.Humanoid.MoveToFinished:Wait() end wait() end end else waypoints = {} end endend
wait(0.1) local function FindNearestTorsoRadiant(position) local minDistance = math.huge local nearestTorso = nil
for i, enemy in ipairs(targetCreepListRadiant) do local distance = (position - enemy:WaitForChild("HumanoidRootPart").Position).Magnitude if distance < minDistance then minDistance = distance nearestTorso = enemy:WaitForChild("HumanoidRootPart") end end return nearestTorsoend
local function FindNearestTorsoDire(position) local minDistance = math.huge local nearestTorso = nil
for i, enemy in ipairs(targetCreepListDire) do local distance = (position - enemy:WaitForChild("HumanoidRootPart").Position).Magnitude if distance < minDistance then minDistance = distance nearestTorso = enemy:WaitForChild("HumanoidRootPart") end end return nearestTorsoend
local function nearestTower(position, faction) local minDistance = math.huge local nearestTower = nil
for _, tower in ipairs(game.Workspace:GetChildren()) do if tower.Name == "Tower1" or tower.Name == "Tower2" or tower.Name == "Tower3" or tower.Name == "Tower4" and tower.Faction.Value ~= faction and tower.Health.Value > 0 then local distance = (position - tower:WaitForChild("BasePart").Position).Magnitude if distance < minDistance then minDistance = distance nearestTower = tower:WaitForChild("BasePart") end end end return nearestTowerend
local enemyTowersRadiant = {} local enemyTowersDire = {}
for i, enemyCreep in pairs(workspace:GetChildren()) do if enemyCreep.Name == "DireCreep" then table.insert(targetCreepListRadiant, enemyCreep) coroutine.wrap(function() while wait() do local nearestTorso = FindNearestTorsoDire(script.Parent.HumanoidRootPart.Position) if nearestTorso and (script.Parent.HumanoidRootPart.Position - nearestTorso.Position).Magnitude < creepsattackrange and nearestTorso.Parent.Faction.Value ~= script.Parent.Faction.Value then attackCreep(script.Parent, nearestTorso.Parent) end local nearestTower = nearestTower(script.Parent.HumanoidRootPart.Position, "Dire") if nearestTower and (script.Parent.HumanoidRootPart.Position - nearestTower.Position).Magnitude < creepsattackrange * 1.9 then fighting = true attackTower(script.Parent, nearestTower.Parent) end end end)() elseif enemyCreep.Name == "RadiantCreep" then table.insert(targetCreepListDire, enemyCreep) coroutine.wrap(function() while wait() do local nearestTorso = FindNearestTorsoRadiant(script.Parent.HumanoidRootPart.Position) if nearestTorso and (script.Parent.HumanoidRootPart.Position - nearestTorso.Position).Magnitude < creepsattackrange and nearestTorso.Parent.Faction.Value ~= script.Parent.Faction.Value then attackCreep(script.Parent, nearestTorso.Parent) end local nearestTower = nearestTower(script.Parent.HumanoidRootPart.Position, "Radiant") if nearestTower and (script.Parent.HumanoidRootPart.Position - nearestTower.Position).Magnitude < creepsattackrange * 1.9 then fighting = true attackTower(script.Parent, nearestTower.Parent) end end end)() end end
if script.Parent.Name == "DireCreep" then for _, creep in ipairs(targetCreepListDire) do Lane(script.Parent, targetCreepListDire, game.Workspace.RadiantAncient, enemyTowersRadiant) end else for _, creep in ipairs(targetCreepListRadiant) do Lane(script.Parent, targetCreepListRadiant, game.Workspace.DireAncient, enemyTowersDire) end end сделай так чтобы скрипт не выдавал ошибки в консоль
- Assistant
Для того, чтобы скрипт не выдавал ошибки в консоль, вам нужно добавить дополнительные проверки на существование объектов и их свойств. Вот пример, как это можно сделать:
local enemyCreeps = {} local enemyTowers = {} for i, enemyCreep in pairs(workspace:GetChildren()) do if enemyCreep.Name == "DireCreep" or enemyCreep.Name == "RadiantCreep" then if enemyCreep:FindFirstChild("HumanoidRootPart") and enemyCreep:FindFirstChild("Humanoid") and enemyCreep.Humanoid.Health > 0 then table.insert(enemyCreeps, enemyCreep) end elseif enemyCreep.Name == "Tower1" or enemyCreep.Name == "Tower2" or enemyCreep.Name == "Tower3" or enemyCreep.Name == "Tower4" then if enemyCreep:FindFirstChild("BasePart") and enemyCreep:FindFirstChild("Health") and enemyCreep.Health.Value > 0 then table.insert(enemyTowers, enemyCreep) end end end coroutine.wrap(function() while true do wait() local nearestCreep = nil local nearestCreepDistance = math.huge for _, enemyCreep in ipairs(enemyCreeps) do if enemyCreep.Name == "DireCreep" and script.Parent.Name == "RadiantCreep" then local distance = (enemyCreep.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude if distance < nearestCreepDistance and distance <= creepsattackrange and enemyCreep.Faction.Value ~= script.Parent.Faction.Value then nearestCreep = enemyCreep nearestCreepDistance = distance end elseif enemyCreep.Name == "RadiantCreep" and script.Parent.Name == "DireCreep" then local distance = (enemyCreep.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude if distance < nearestCreepDistance and distance <= creepsattackrange and enemyCreep.Faction.Value ~= script.Parent.Faction.Value then nearestCreep = enemyCreep nearestCreepDistance = distance end end end if nearestCreep then attackCreep(script.Parent, nearestCreep) else for _, enemyTower in ipairs(enemyTowers) do local distance = (enemyTower.BasePart.Position - script.Parent.HumanoidRootPart.Position).Magnitude if distance <= creepsattackrange * 1.9 and enemyTower.Faction.Value ~= script.Parent.Faction.Value then attackTower(script.Parent, enemyTower) break end end end end end)()Этот измененный код проверяет наличие необходимых свойств и объектов перед их использованием, чтобы избежать ошибок. Вы также должны добавить проверки наличия объектов и реализацию функций
attackCreepиattackTowerв вашем оригинальном скрипте для удаления всех ошибок.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.