So I wanted to make script which detected player and then made npc follow it. this is script
while wait(1) do model = script.Parent dist = 30 target = nil for i ,v in pairs(game.workspace:GetChildren()) do humanoid = v:FindFirstChild("Humanoid") torso = v:FindFirstChild("UpperTorso") if humanoid and torso and v ~= script.Parent then if humanoid.Health > 0 then if (model.Union.Position - torso.Position).magnitude < dist then dist = (model.Union.Position - torso.Position).magnitude target = torso if torso then model.Humanoid:MoveTo(torso.Position , torso) end end end end end end
but it doesnt seem to be working, maybe because i have made custom npc, how can i solve this problem?