Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wait(.7)
- --variables
- local pathfinding = game:GetService("PathfindingService")
- local debris = game:GetService("Debris")
- local tweenservice = game:GetService("TweenService")
- local mob = script.Parent
- local humanoid = mob:WaitForChild('Humanoid')
- local humanoidrp = mob:WaitForChild('HumanoidRootPart')
- local torso = mob:WaitForChild('Torso')
- local attack1 = true
- local attack2 = true
- local attack3 = true
- local function findnearbyplayers()
- local dist = 5000
- local plr = nil
- for i,v in pairs(game.Workspace:GetChildren()) do
- if v:FindFirstChild('Humanoid') and v.Name ~= 'Dummy' then
- local hum = v:FindFirstChild('Humanoid')
- local humroot = v:FindFirstChild('HumanoidRootPart')
- local mag = (humanoidrp.Position-humroot.Position).Magnitude
- if mag < dist and hum.Health > 0 then
- mag = dist
- plr = humroot
- end
- end
- end
- return plr,dist
- end
- local function getunstuck()
- local pos = humanoidrp.Position + Vector3.new(math.random(-30,30),0,math.random(-30,30))
- humanoid:MoveTo(pos)
- humanoid.Jump = true
- end
- local function checksight(target)
- local ray = Ray.new(humanoidrp.Position,(target.Position-humanoidrp.Position).Unit*20)
- local hit,position = game.Workspace:FindPartOnRayWithIgnoreList(ray,{script.Parent})
- if hit then
- if hit:IsDescendantOf(target.Parent) then
- return true
- end
- end
- return false
- end
- local function pathfind()
- local target = findnearbyplayers()
- if not target then
- local path = pathfinding:CreatePath()
- local rand = humanoidrp.Position + Vector3.new(math.random(-50,50),0,math.random(-50,50))
- path:ComputeAsync(humanoidrp.Position,rand)
- local waypoints = path:GetWaypoints()
- for i,v in pairs(waypoints) do
- if Enum.PathWaypointAction.Jump == v.Action then
- humanoid.Jump = true
- end
- print('no')
- humanoid:MoveTo(v.Position)
- local movefinished = humanoid.MoveToFinished:Wait()
- if not movefinished then
- getunstuck()
- break
- end
- end
- else
- local path = pathfinding:CreatePath()
- path:ComputeAsync(humanoidrp.Position,target.Position)
- local waypoints = path:GetWaypoints()
- for i,v in pairs(waypoints) do
- if Enum.PathWaypointAction.Jump == v.Action then
- humanoid.Jump = true
- end
- print('yes')
- humanoid:MoveTo(v.Position)
- spawn(function()
- if humanoid.WalkToPoint.Y > humanoidrp.Position.Y then
- humanoid.Jump = true
- end
- end)
- local movefinished = humanoid.MoveToFinished:Wait()
- if not movefinished then
- getunstuck()
- break
- end
- if checksight(target) and math.abs(math.abs(humanoidrp.Position.Y) - math.abs(target.Position.Y)) < 3 then
- break
- end
- if i % 5 == 0 then
- if findnearbyplayers() ~= target then
- break
- end
- end
- end
- end
- end
- local function main()
- local target = findnearbyplayers()
- if target then
- print('B')
- if checksight(target) and math.abs(math.abs(humanoidrp.Position.Y) - math.abs(target.Position.Y)) < 3 then
- pathfind()
- else
- pathfind()
- end
- end
- end
- while true do
- if humanoid.Health < 1 then
- break
- end
- main()
- wait()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement