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

roblox npc not moving to character with moveto()?

Asked by 5 years ago
Edited 5 years ago

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?

1
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 Gameplayer365247v2 1055 — 5y
0
Please put it in a script block, it is unreadable this way.. CaptainAlien132 225 — 5y
0
yes but problem is that my custom npc doesnt have humanoid root part i just assembled it with some parts ReziGamer123 0 — 5y

Answer this question