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
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.