Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago

Hello! I made this script thanks to a YT video: ~~~~~~~~~~~~~~~local function FindTarget() 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

Log in to vote
0
Answered by 2 years ago

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.

Ad

Answer this question