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

Can someone help me with pathfinding? I can't find where it moves to the next node.

So what I'm having trouble with is launching this game.ReplicatedStorage.BossDeath:FireAllClients("BossDeath") when 1 of the bosses or "Wallbreakers" reach the node there is only 1 node, but when I do:


local reached = humanoid.MoveToFinished:wait()
if reached then 
print("test")
game.ReplicatedStorage.BossDeath:FireAllClients("BossDeath")
end

But when I do that it doesn't do anything works not even the print, here's my code:

local p=game:GetService("PathfindingService")
p.EmptyCutoff=0
local nodes={}
for _,v in pairs(workspace:GetChildren())do
	if v.Name=="Node"then
		nodes[#nodes+1]=v
	end
end

for _,v in pairs(workspace.WallAttackers:GetChildren())do
	spawn(function()
		local torso,humanoid=v:WaitForChild("HumanoidRootPart"),v:WaitForChild("Humanoid")
		torso.Touched:connect(function()
			wait(math.random())
			humanoid.Jump=true
		end)
		local walk;
		walk=function()
			local target=nodes[math.random(#nodes)]
			local path=p:ComputeSmoothPathAsync(torso.Position,target.Position,500)
			if path.Status.Name=="Success"then
				local points=path:GetPointCoordinates()
				for i,point in pairs(points)do
					local part,P=workspace:FindPartOnRay(Ray.new(point,Vector3.new(0,-10,0)))
					if part then
						point=P
						points[i]=P
					end
				end
				local distance;
				for i=1,#points do
					local point=points[i]
					humanoid:MoveTo(point)
					local jump;
					if point.Y>=torso.Position.Y-1.5 then
						humanoid.Jump=true
						jump=humanoid.Changed:connect(function()
							humanoid.Jump=true
						end)
					end
					local reached = humanoid.MoveToFinished:wait()
					if jump then
						jump:disconnect()
					end
					if reached then 
					print("test")
					game.ReplicatedStorage.BossDeath:FireAllClients("BossDeath")
					end
					if not reached then
						return walk()
					end
				end
			else
				humanoid:MoveTo(torso.CFrame*Vector3.new(0,0,5))
				humanoid.MoveToFinished:wait()
					
			end
			return walk()
		end
		walk()
	end)
end

Hope someone knows how to help me. This is my first post on the site

1 answer

When using pathfinding. EmptyCutoff cannot be zero. This value must be set over 0 so the service can determine if a empty voxel is in the radius. (The radius is set by :ComputeSmoothPathAsync)

The default is 0.16 so just set it below that but not too low like at zero. Otherwise, set it at default or higher if you prefer.

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