✓ Accepted answer
Typed all of this on mobile so please correct me if anything is wrong!
:CreatePath() uses a dictionary, which is like a table with variables inside it. You’re directly putting the arguments in the function, so that’s not going to work.
You’re also using the wrong arguments. :CreatePath() in PathfindingService doesn’t actually “calculate” the path, it only creates it. The created path is what you use to calculate the path.
:CreatePath() in PathfindingService has three parameters :
- AgentRadius (How far humanoid separates from obstacles)
- AgentHeight (Minimum height that humanoid can go through)
- AgentCanJump (If the humanoid is allowed to jump instead of only walk)
This is how you would use it correctly in your script :
In one line :
path = game:GetService("PathfindingService"):CreatePath({AgentRadius = 2, AgentHeight = 5, AgentCanJump = true})
In multiple lines :
local Dictionary = {}
Dictionary.AgentRadius = 2
Dictionary.AgentHeight = 5
Dictionary.AgentCanJump = true
path = game:GetService("PathfindingService"):CreatePath(Dictionary)
(Note leaving arguments blank would make it use the default value)
Also if you’re also confused to where these variables came from, you can find it here.
After all of that is done, a Path instance is created. From it, you can use :ComputeAsync() to calculate the path and :GetWaypoints() to get each point the humanoid is supposed to follow to get to the goal.
You can learn more about pathfinding here.
Hope this helped! If you have any questions, please comment!
3 comments
ye im quite sure pathfinding cant work with 1 line of code
its not literally pathfinding ok? it prob is a sequence where it recommends u the nearest node to go to
so u have to repeatedly fire it