Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why will my NPC not move from pointA to B?

I am following a roblox wiki tutorial but the script seems to not be working, the code is contained in a localscript inside of the npc, I get no errors when I run the game but alas the npc will not move. the npc is r6

-- Variables for the npc and its humanoid
local npc = game.Workspace.NPCmodel
local humanoid = npc.Humanoid

-- Variables for the point(s) the npc should move between
local pointA = game.Workspace.coffeeMachine
local pointB = game.Workspace.Model

-- Move the npc to the primary part of the green flag model
humanoid:MoveTo(pointA.PrimaryPart.Position)

-- Wait until the npc has reached its first target
humanoid.MoveToFinished:Wait()

-- Move the npc to the primary part of the purple flag model
humanoid:MoveTo(pointB.PrimaryPart.Position)

2 answers

✓ Accepted answer

try to remove primary part

-- Variables for the npc and its humanoid
local npc = game.Workspace.NPCmodel
local humanoid = npc.Humanoid

-- Variables for the point(s) the npc should move between
local pointA = game.Workspace.coffeeMachine
local pointB = game.Workspace.Model

-- Move the npc to the primary part of the green flag model
humanoid:MoveTo(pointA.Position)

-- Wait until the npc has reached its first target
humanoid.MoveToFinished:Wait()

-- Move the npc to the primary part of the purple flag model
humanoid:MoveTo(pointB.Position)

also make sure that the NPC don't have anything anchored, arms, head, torso, etc.

2 comments

0

Wow, I forgot to check if the hrp was unanchored, removng the primary part is not a good idea though as models themselves don't have positions so lua gets confused and doesn't know where to move

0

oh ye its a model

Localscripts will not work inside of an NPC. From what i can see, this is the only error.

LocalScripts only work when used as a descendant to the player or player's character

Consider changing to a server script (aka a normal script)

3 comments

0

hmmm, still doesn't seem to work, the character is r6 if that changes anything

0

try doing humanoid.MoveToFinished:Connect(function() print("MovementComplete") end) before the :Wait() statement and see if that works

0

let me know if that prints

This discussion is preserved as it was. New answers, comments, and votes are closed.