Hey guys, I was working with some PathfindingService, and then I came to a error. My character never moved. I'll show you all my code now! Here's the code:
local PathfindingService = game:GetService("PathfindingService")
local MiniToon = game.Workspace:WaitForChild("MiniToon")
local Humanoid = game.Workspace.MiniToon:WaitForChild("Humanoid")
local endPointBrain = game.Workspace:WaitForChild("EndPointBrain")
local path = PathfindingService:CreatePath()
path:ComputeAsync(MiniToon.HumanoidRootPart.Position, endPointBrain.PrimaryPart.Position)
local waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
local part = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.4, 0.4, 0.4)
part.Position = waypoint.Position
part.Anchored = true
part.CanCollide = false
part.Parent = game.Workspace
end
wait(10)
Humanoid:MoveTo(waypoints.Position)
Humanoid.MoveToFinished:Wait()
In my error message, it said Workspace.MiniToon.Script:10: attempt to index nil with 'Position'
I don't understand where it went wrong.
Sincerely,
Ducksneedhelp - Scripter

1 comment
Waypoints is an array, you're not referencing any Instance alone; the Position property doesn't exist in this context. You'll need to iterate through each Waypoint and use MoveTo respectively, along with MoveToFinished.