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

why doesnt my humanoid follow the path made by pathfindingservice?

while true do
path = game:GetService('PathfindingService'):ComputeRawPathAsync(game.Workspace.SkullHollow.Torso.Position,game.Workspace.finish.Position,200)
points = path:GetPointCoordinates()


for p = 1,#points do
	part = Instance.new('Part')
	part.FormFactor = Enum.FormFactor.Symmetric
	part.CanCollide = false
	part.Size = Vector3.new(1,1,1)
	part.Position = points[p]
	part.Anchored = true
	part.Parent = game.Workspace.Points
	
end
wait(.1)
	game.Workspace.SkullHollow.Humanoid:MoveTo(game.Workspace.finish.Position)
end

1 answer

Because your ordering the humanoid to move to the position of the 'finish' spot! Rather than the current iteration in the pathfinding table.

--Define this up here just to clean up the code
local pathfinding = game:GetService("PathfindingService")
--since you use these multiple times, define a variable for ease of use.
local skhollow = workspace.SkullHollow
local finish = workspace.finish

while wait(.1) do
	--Clean this up a bit
	local path = pathfinding:ComputeRawPathAsync(
		skhollowTorso.Position,finish.Position,200
	)
	local points = path:GetPointCoordinates()
	for p = 1,#points do
		part = Instance.new('Part',workspace.Points)
		part.FormFactor = Enum.FormFactor.Symmetric
		part.CanCollide = false
		part.Size = Vector3.new(1,1,1)
		part.Position = points[p]
		part.Anchored = true
		--Move it to the current iteration in the pathfinding table.
		skhollow.Humanoid:MoveTo(points[p])
	end
end

Note: with the excessive spawning of parts, it will soon start to clutter your workspace. You may want to delete the parts using the Destroy function

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