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

How can I enchant this following script so the NPC can do mazes?

Hello! I made this script thanks to a YT video:

	local maxDistance = 100000
	local target = nil
	for i,v in pairs(workspace:GetChildren()) do
		if v:FindFirstChild("Humanoid") then
			if (v.Head.Position-script.Parent.Head.Position).magnitude < maxDistance then
				target = v.Head
			end
		end
	end
	return target
end

while wait() do
	local target = FindTarget()
	if target then
		script.Parent.Humanoid:MoveTo(target.Position)
	end
end~~

Anyway there Is a problem (Well two but lets do the one I actually wanna do). So I want the NPC to know how to do mazes, a example would be where the NPC sees a player behind the wall and needs to turn around the wall to get the player

1 answer

What you are describing is path finding. You have to get the pathfinding service, find the closest player, then use pathfinding service to plot a path from the NPC to the target. The pathfinding service will automatically make the NPC walk to each point along the computed path.

https://youtu.be/q7C4noy1uOk

Check this out.

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