- What do you want to achieve? Keep it simple and clear!
I’m trying to figure out how I would add pathfinding to this code. The NPC is able to follow me and stops walking once they’re close enough. If I go through a doorway they get stuck.
local distance = sets["Maximum Distance (In Studs)"].Value
for _, player in ipairs(players:GetPlayers()) do
local char = player.Character or player.CharacterAdded:Wait()
local target = char:FindFirstChild("HumanoidRootPart")
if target then
if (target.Position - hrp.Position).Magnitude <= distance then
script.Parent.Humanoid:MoveTo(target.Position, target)
if (hrp.Position - target.Position).Magnitude < stopStudAmount and shouldStop.Value then
script.Parent.Humanoid:MoveTo(hrp.Position, hrp)
end
end
end
end
end