Function when npc reaches part with pathfinding

I wanna make it so when the npc reaches the part after MoveTo is done it fires a event such as print(“Hello”)
Screenshot 2022-05-27 161334

when it reaches the part it gives a error
image

Ive tried multiple methods but none seem to work

Here is the code

I’m not good with npcs in the slightest but is it possible to use MoveToFinished in its place?
looked it up and in every example I can’t see reached mentioned anywhere the only thing people use is MoveToFinished to detect this type of stuff

That keeps firing when its going to the part it never only fires once its reached the part

I’ll try pull out a example of what I’ve found but can you show me a link about reached?


it was this but i realized its for a module

Hmm maybe if it detects collision with the goal then it will activate a function would this cheep fix work here?

image

it gives this error

This did not work thanks anyways

Have you tried printing waypoints.Reached? It might be an Boolean.

I did i put print(“Hello”) and it just did not work when it would reach the part it would give a error

Yes but have you tried printing waypoints.Reached like this?:

print(waypoints.Reached)

It might not be an RBXScriptSignal.

Im trying to add a function like workspace.Part.Transparency = 1 when the npc reaches the part

What happens when you add that directly after the MoveToFinished?

it repeats it even when the npc has not reached the part

could just put the print(‘HI’) after the for loop

or setup the for loop to see when it finishes moveto on the last waypoint

for i, waypoint in ipairs(waypoints) do
	NPCHum:MoveTo(waypoint.Position)
	NPCHum.MoveToFinished:Wait()
	if i == #waypoints then
		print('THE END')
	end
end

you could also do distance checks on each loop

for i, waypoint in ipairs(waypoints) do
	NPCHum:MoveTo(waypoint.Position)
	NPCHum.MoveToFinished:Wait()
	
	if (NPCChar.HumanoidRootPart.Position - End.Position).Magnitude <= 8 then  -- you can change the 8 lower if you need or higher 
		print('THE END')
		break  -- break out no need to go any further
	end	
end