function AI:CreatePath(Destination : Vector3)
local NewDestination = self.CurrentPatrolPoint or Destination
local AgentParams = {
["AgentRadius"] = self.AgenRadius,
["AgentHeight"] = self.AgentHeight,
["AgentCanJump"] = self.AgentCanJump
}
self.CurrentPatrolPoint = NewDestination
local Path = PathFindingService:CreatePath(AgentParams)
print("Printing here: "..self.RootPart.Name)
Path:ComputeAsync(self.RootPart.Position,Destination)
return Path
end
function AI:CanSeeTarget(target)
local RayCastParams = RaycastParams.new()
RayCastParams.FilterDescendantsInstances = {self.Model}
RayCastParams.FilterType = Enum.RaycastFilterType.Exclude
local Orgin = self.RootPart.Position
local Direction = (target.RootPart.Position - self.RootPart.Position).Unit
local raycastResult = workspace:Raycast(Orgin, Direction * self.SightDistance, RayCastParams)
if raycastResult and raycastResult.Instance then
if raycastResult.Instance:IsDescendantOf(target) then
return true
else
return false
end
else
return false
end
end
function AI:MoveToPath (NewPath: Path)
local Waypoints = NewPath:GetWaypoints()
print(self.RootPart)
print(self.Model)
print(self.MaxChaseDistance)
end
This is my module Script
-- AI Module --
local AI_NPC = AI_Module.InnitAICharacter(NPC,WaypointsFolder,SFXFolder,script)
Humanoid.Died:Connect(function()
AI_NPC:ChangeState(AI_NPC.States.Dead)
end)
while task.wait(0.3) do
local Waypoint = AI_NPC:GetRandownWayPoint()
local Path = AI_NPC:CreatePath(Waypoint.Position)
AI_NPC:MoveToPath(Path)
end
This is my Server Script
In the Module Function, MoveToPath as well as CreatePath , i can get the self variables set but when i tried to access an element inside the self table on CanSeeTarget , so here RootPart is nil while its returning the RootPart object in MoveToPath as well as create path