Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Pathfindingservice won't work, "Unable to cast to Dictionary".????????

I made a little map and I want to try Pathfindingservice on it, it just says "Unable to cast to Dictionary"

here is my code. if someone can help that would be awesome.

path = game:GetService("PathfindingService"):CreatePath(game.Workspace.Start.Position, game.Workspace.Finish.Position, 100)

3 comments

0

ye im quite sure pathfinding cant work with 1 line of code

0

its not literally pathfinding ok? it prob is a sequence where it recommends u the nearest node to go to

0

so u have to repeatedly fire it

1 answer

✓ 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 :

--Not sure if I did this one correctly
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!

This discussion is preserved as it was. New answers, comments, and votes are closed.