Here is the script ( Server Script ):
--------------------- AI is in R6 -----------------------------
local PathFindingService = game:GetService("PathfindingService")
local Humanoid = script.Parent:WaitForChild("Humanoid")
local Torso = script.Parent:WaitForChild("Torso")
local EndingPoint = game.Workspace:WaitForChild("EndingPoint") --- this is just a part
local path = PathFindingService:CreatePath()
local WayPointsList = {}
local Limiter = 0 --- Number We gonna use to limit the path
wait(.5)
while true do ---- this is going to run every .2 Seconds
wait(.2)
path:ComputeAsync(Torso.Position,EndingPoint.Position) ---- Generating the path
local waypoints = path:GetWaypoints() --- Getting the way points
for i,Waypoint in pairs(waypoints) do ---- Looping through all the way points
if Limiter < 2 then ---- if the number is less than 2 it will add a waypoint to the list else if it is bigger it will break
table.insert(WayPointsList,Waypoint) -- ading the waypoint
Limiter = Limiter + 1 --- adding one Limiter so we can limit the path
print(Limiter)
else ---- if the number is bigger than 2 or equal then it will break
break
end
end
for i,inList in pairs(WayPointsList) do ---- looping through the List
if Limiter == 2 then -- making sure the number is equal to 2
Humanoid:MoveTo(inList.Position) --- moving the npc to the listed waypoint
Limiter = 0 --- reseting the limiter
table.remove(WayPointsList,inList) --- removing the way point from the list
Humanoid.MoveToFinished:Wait() --- waiting till the AI has reached the point
else
end
end
end
Please Read the script First so you can understand the rest
So What am i trying to do here is limit the Path So can the AI PROPERLY Reach/Follow the Part ( if the path isn't limited it wont follow properly because the part is moving ) by limiting it that means it resets the current position of the part every 2 waypoints that the npc moved to and then generates a new path and new waypoints, so it can keep on track of the moving part
Why did i add a limter you may ask? because it limits the added Waypoints to the table
Output: Empty.
THE ISSUE:
Nothing is being printed out nor the AI is moving
