Hi everyone, I’m trying to make a simple guard class using Nevermore and OOP however when I call my StartPatrol method after 1 loop it clears the descendants of the folder?
--[=[
@class MyClass
]=]
local Promise = require(game.ServerScriptService.Dependencies.promise)
local require = require(script.Parent.loader).load(script)
local Maid = require("Maid")
local BaseObject = require("BaseObject")
local GuardClass = setmetatable({}, BaseObject)
GuardClass.ClassName = "GuardClass"
GuardClass.__index = GuardClass
function GuardClass.new(Guard, PathfindingService)
local self = setmetatable(BaseObject.new(), GuardClass)
self._guard = Guard
self._humanoid = self._guard.Humanoid
self._waypoints = self._guard.Waypoints
self._animator = Instance.new("Animator")
self._animator.Parent = self._humanoid
self._maid = Maid.new()
local IdleAnimId = "http://www.roblox.com/asset/?id=180435571"
local WalkAnimId = "http://www.roblox.com/asset/?id=180426354"
local IdleAnim = Instance.new("Animation")
local WalkAnim = Instance.new("Animation")
-- Assign properties
IdleAnim.AnimationId = IdleAnimId
IdleAnim.Name = "Idle"
WalkAnim.AnimationId = WalkAnimId
WalkAnim.Name = "Walk"
self._walkAnim = self._animator:LoadAnimation(WalkAnim)
self._idleAnim = self._animator:LoadAnimation(IdleAnim)
self._pathfindingService = assert(PathfindingService, "No pathfindingservice")
self:StartPatrol()
return self
end
function GuardClass:StartPatrol()
while true do
task.wait(0.1)
for i, waypoint in ipairs(self._waypoints:GetDescendants()) do
self:_RequestNewPath(waypoint.Position):catch(warn):await()
print(string.format("[Guard Controller] - %s Has reached Waypoint #%d", self._guard.Name, i)) -- Once the first waypoint is reached the descendants in the waypoints folder are deleted
task.wait(2)
end
print(string.format("[Guard Controller] - %s's Patrol has finished.", self._guard.Name)) -- Finishs the for loop here
end
end
function GuardClass:_RequestNewPath(destination: Vector3)
return Promise.new(function(succ, err)
self
._pathfindingService
:FindPath(self._guard.PrimaryPart.Position, destination) -- Access a service "Pathfinding Service"
:andThen(function(val)
local t = self:MoveGuard(val)
if t then
succ()
end
end)
:catch(warn)
:await()
end)
end
function GuardClass:MoveGuard(Waypoints: table)
for _, waypoint in Waypoints do
self._walkAnim:Play()
self._idleAnim:Stop()
self._humanoid:MoveTo(waypoint.Position)
self._humanoid.MoveToFinished:Wait(2)
self._walkAnim:Stop()
self._idleAnim:Play()
end
return true
end
function GuardClass:Destroy()
self._maid:DoCleaning()
end
return GuardClass
Is it a problem with how I get descendants, how I request paths, or something else