sigh I been working for 5 days straight on this super smart AI and I can't figure out why it doesn't work. I looked over line of line of code and I found ONE error holding me BACK. The Path Finding Service keeps returning nil with ALL my positions. For example, I have a function which looks like so:
local function PathFinder(V31, V32) local Path = game:GetService("PathfindingService"):CreatePath():ComputeAsync(V31, V32) print(Path) if Path then return Path:GetWaypoints() else return {V32} end end
Every time i put the two vectors into the function the script responds with nil. For example I would have a part at the coordinates 0, 0, 0 and I would use Pathfinder to get to 10, 0, 10 and this would be its response:
nil
And sometimes it would error (when I ran it in command bar):
local path = game:GetService("PathfindingService"):CreatePath()
local BHRP = workspace["Smart AI"].HumanoidRootPart.Position local Part = workspace.Part.Position path = path:ComputeAsync(Vector3.new(BHRP.X, 0, BHRP.Y), Vector3.new(Part.X, 0, Part.Z)) pa:2: attempt to index nil with 'GetWaypoints'
If you could assist me in any way possible I would be extremely grateful.
Create path once for every humanoid
Read about PathfindingService first and see all of it's functions. You are using CreatePath which is fine but you are not using it right, first, you should create path once and keep it's variable, you don't need to create new path every time you call PathFinder
... Even tho this won't solve your problem, you need to have reference of the Path
object.
ComputeAsync returns nil
ComputeAsync does not return anything, it is not supposed to, it computes current path so all you have to do is call it and then use Path:GetWaypoints on the Path
.
local Path = game:GetService("PathfindingService"):CreatePath() local function PathFinder(V31, V32) Path:ComputeAsync(V31, V32) return Path:GetWaypoints() end
Also make sure to use proper formatting - tabs, you script looks like a dog shit without them... (not hate, just a constructive feedback)