Making a Model move like an NPC

Hey All,

I’m trying to make a basic model move around like an NPC when using commands like humanoid:MoveTo and PathfindingService:CreatePath(). I tried applying the principles given in Roblox’s Moving NPCs Between Points tutorial page. My design is not working.

Here’s my very basic setup. To create the model that will move, I started with a basic part, colored blue, named PartA and grouped it alone into a Model named ModelA. PartA was set as the PrimaryPart of the Model. A Humanoid was added within the Model.
ModelA

For the destination point I added a Model named GreenFlag. The Pole part of the is set as the PrimaryPart.
GreenFlag

Finally I added a Script within the ModelA, telling ModelA to move to the GreenFlag.
Here’s the script:

-- Variables for the ModelA and its humanoid

local modelA = game.Workspace.ModelA

local humanoid = modelA.Humanoid

-- Variable for the point the modelA should move to

local greenFlag = game.Workspace.GreenFlag

-- Move the modelA to the primary part of the green flag model

humanoid:MoveTo(greenFlag.PrimaryPart.Position)

Here’s the game screenshot

The Model just sits there an makes no effort to move toward GreenFlag at all. I’m guessing that maybe the Model needs more than just Humanoid added to it to behave like an NPC and follow commands like humanoid:MoveTo . Can anyone point out what more is needed to make the Model behave and move like an NPC would?

1 Like

:MoveTo() will not work on a regular model that isn’t rigged and made as a humanoid/npc, you will have to use TweenService:

local TweenService = game:GetService("TweenService")

local Part = --Your part
local TweenInfo = tweeninfo.new(1)--you can add more parameters to make it more detailed
local Goals = {Position = vector3.new(--[[yourpositionhere]])}
local Tween  = TweenService:Create(Part,TweenInfo,Goals)

Tween:Play()

If you want to move models you would have to weld the parts that the model is made with together and move only one of them, unanchor the others. There is an article on TweenService here: TweenService | Documentation - Roblox Creator Hub

That’s a good suggestion. Is there a way to further modify the Model to become an NPC so that it will respond to the MoveTo commands? Would additional items need to be added to the Model like HumanoidRootPart and/or others?

1 Like

Instead of building an ordinary model, you need to make a rigged npc. This tutorial will show you how.

2 Likes

Will the thing you are moving be just a part or an actual NPC? If it is not an NPC I do not recommend using humanoids if they are not necessary as they can lag the server.

I am going to make a simple, square shaped, robot that would move around.

This topic needs to be in the #help-and-feedback:scripting-support
Please change your topic category.

My question isn’t about what scripting commands to use, but which objects should be added to a Model to make it behave like an NPC. I assumed that adding objects to Models would be a Building help issue.

I watched the video suggested above, which was insightful. I didn’t need to add any animations to my basic Part. Still I did learned how to make a basic part move. Here’s the basic recipe:

Steps:

  1. Make a part
  2. Group the part
  3. Duplicate the part with collisions off so the duplicate is in the same position as the part
  4. Rename the duplicate to HumanoidRootPart
  5. Add a WeldConstraint to the part
  6. In the WeldConstraint properties, set Part0 to the Part. Set Part1 to HumanoidRootPart
  7. Under the Model add a Humanoid
  8. Under Model create the Script for moving the part as mentioned initially in the post

Capture2

With that, a basic part or simple model can respond to movement commands like an NPC.

2 Likes