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

Why will my NPC not move from pointA to B?

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
1
Answered by 3 years ago

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.

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 MOREHOURSOFFUN 104 — 3y
0
oh ye its a model MacGames007 114 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)

0
hmmm, still doesn't seem to work, the character is r6 if that changes anything MOREHOURSOFFUN 104 — 3y
0
try doing humanoid.MoveToFinished:Connect(function() print("MovementComplete") end) before the :Wait() statement and see if that works Heavenlyblobmaster 271 — 3y
0
let me know if that prints Heavenlyblobmaster 271 — 3y

Answer this question