Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local zombie = script.Parent.Parent
- local CollectionService = game:GetService("CollectionService")
- local PathfindingService = game:GetService("PathfindingService")
- local TweenService = game:GetService("TweenService")
- local PatrolNodes = CollectionService:GetTagged("ZombiePatrolNode")
- local possiblePatrolNodes = {}
- for _, node in pairs(PatrolNodes)do
- if node:IsDescendantOf(workspace)then
- table.insert(possiblePatrolNodes, node)
- end
- end
- local DRAWDEBUG = {}
- local function run()
- if zombie.Brain.Patrolling.Value == false and zombie.Brain.LockedOn.Value == nil and zombie.Brain.ServerControl.Value == true then
- zombie.Brain.Patrolling.Value = true
- local path = nil
- repeat
- wait()
- local NodeSel = possiblePatrolNodes[math.random(1, #possiblePatrolNodes)]
- path = PathfindingService:CreatePath({AgentRadius = 5, AgentHeight = 5, AgentCanJump = false})
- path:ComputeAsync(zombie.HumanoidRootPart.Position, NodeSel.Position)
- if path.Status == Enum.PathStatus.Success then
- break
- else
- zombie.Humanoid.Jump = true
- zombie.Humanoid:Move(Vector3.new(zombie.HumanoidRootPart.Position.X + math.random(-1,1), zombie.HumanoidRootPart.Position.Y, zombie.HumanoidRootPart.Position.Z + math.random(-1,1)))
- end
- until 1 + 1 == 3
- local PatrolPath = path:GetWaypoints()
- for _, waypoint in pairs(PatrolPath)do
- if zombie.Brain.ServerControl.Value == false then return end
- zombie.Humanoid:MoveTo(waypoint.Position)
- repeat wait() until (zombie.HumanoidRootPart.Position - waypoint.Position).Magnitude <= 10
- end
- zombie.Brain.Patrolling.Value = false
- for _, obj in pairs(DRAWDEBUG)do
- obj:Destroy()
- end
- DRAWDEBUG = {}
- end
- end
- if script.Parent.Parent:IsDescendantOf(game.Workspace.Zombies) then run(); wait(1); zombie.Brain.Patrolling.Value = false; end
- zombie.Brain.Patrolling.Changed:Connect(function(val) if val == false then run() end end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement