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?

3 comments
use humanoidrootpart instead with CFrame, remember that cframe is used by CFrame = CFrame.new(position) cframe cant be set to a position using cframe at the end like many do. an example of mistakes many do is they do CFrame = CFrame.new(game.Workspace.Part.CFrame) insted of CFrame = CFrame.new(game.Workspace.Part.Position) which it should be and damn this comment is long now
Please put it in a script block, it is unreadable this way..
yes but problem is that my custom npc doesnt have humanoid root part i just assembled it with some parts