PageSourceSearch

https://www.lualearning.org/assets/17e02441-d96a-48e2-a0a4-068a4def29e7-_lonDIHF.js

js lualearning.org collected 2026-10-08 16:37:07 UTC 3,356 bytes, 108 lines download raw bytes

1const t=`To use "*PathfindingService*" you will need to put a script inside of the character, otherwise it won't work.
2
3So first of all you need to define a character.
4
5
6\`\`\`Lua
7local character = script.Parent
8\`\`\`
9
10We are accessing a character and now let's make it simple.
11
12
13\`\`\`Lua
14local character = script.Parent
15local humanoid = character:FindFirstChild("Humanoid")
16local part = workspace.Part
17
18humanoid:MoveTo(part.Position)
19\`\`\`
20As you can see we defined the humanoid to access something that is called MoveTo,
21
22
23humanoid:MoveTo() will allow the character to move.
24
25
26![image|200x200](/assets/16300558517.jpg)
27
28
29And we defined a part to move the character to.
30
31but the sad thing is if we add a wall and cover the path this will happen.
32
33
34
35![image|100x100](/assets/16300593778.jpg)
36
37Unfortunately it will get stuck because it doesn't find the closest path it just goes to the path in sight.
38
39
40That's where "*PathfindingService*" come along!
41
42
43You might be asking, what does "PathfindingService" do?
44
45Well fortunately it's really easy to use but if you are a beginner you might not understand, so I recommend you to be intermediate to read the documentation about "*PathfindingService*".
46
47
48Okay the first thing to use "*Pathfindingservice*" is to define it.
49
50\`\`\`Lua
51local PathfindingService = game:GetService("PathfindingService")
52local path = PathfindingService:CreatePath()
53\`\`\`
54
55So now we defined "*PathfindingService*", and we defined a variable that's called "*path*"
56
57so path = PathfindingService:CreatePath() actually creates a path but it's imaginary so it's stored but it's not quite correct yet.
58
59To make it correct you'll have to compute the path!
60
61\`\`\`Lua
62local PathfindingService = game:GetService("PathfindingService")
63local path = PathfindingService:CreatePath()
64
65path:ComputeAsync(character.HumanoidRootPart.Position, workspace.Part.Position) -- Start Pos, End Pos
66\`\`\`
67
68So this looks confusing, but don't worry it's quite simple.
69
70First of all we computed the path and we said the start position of our path and the end position.
71
72So you might think that we are done, but we are close.
73
74\`\`\`Lua
75local PathfindingService = game:GetService("PathfindingService")
76local path = PathfindingService:CreatePath()
77
78path:ComputeAsync(character.HumanoidRootPart.Position, workspace.Part.Position) -- Start Pos, End Pos
79
80local waypoints = path:GetWaypoints()
81
82\`\`\`
83
84You might get confused but we defined waypoints, so waypoints = path:GetWaypoints()
85
86So path:GetWaypoints() just get's the imaginary parts and it's basically a table with all the imaginary parts.
87
88
89\`\`\`Lua
90local PathfindingService = game:GetService("PathfindingService")
91local path = PathfindingService:CreatePath()
92
93path:ComputeAsync(character.HumanoidRootPart.Position, workspace.Part.Position) -- Start Pos, End Pos
94
95local waypoints = path:GetWaypoints()
96
97for i, waypoint in pairs(waypoints) do
98	humanoid:MoveTo(waypoint.Position)
99	humanoid.MoveToFinished:Wait()
100end
101\`\`\`
102
103So we made a for loop to loop to all the imaginary parts, so instead of saying waypoints[1] we just loop all of this.
104
105And humanoid:MoveTo(waypointPosition) just moves the character to the waypoints so it follows the right path instead of ignoring everything in sight and that's basically "*PathfindingService*"
106
107It just makes a path and ignore obstacles.
108`;export{t as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.