Trying to make an NPC (model) move to a random part in an area

Hello, I’m trying to make a model move around to different parts in a house, i’ve named them nodes.
Unfortunately the script Im using does not give an error, and the model is not anchored.

Inside the NPC:
image

the script:


local Humanoid = Character.Humanoid

for i,v in pairs(game.Workspace.Nodes:GetChildren()) do

Humanoid:MoveTo(v.Position, v)

Humanoid.MoveToFinished:Wait(1)

end

The nodes are the red parts.


Can someone please help?

local Nodes = workspace.Nodes
for i,v in pairs({Nodes:GetChildren()}) do
   local r = math.random(1, #v)

end

try v[math.random(1, #v)] if that doesmnt work

The code you provided did not work. When I ran it, it did not give an error either.

Does he have a HumanoidRootPart? I can’t remember if that’s required or not for a humanoid to move around.

Anyway:

function PickRandom(Hum: Humanoid?)
local children = Nodes:GetChildren() -- returns a table of Instances
local new = children[math.random(1, #children)] -- Picks a Random instance

if new then -- if Instance
Hum:MoveTo(new.Position) -- MoveTo Instance
Hum.MoveToFinished:Wait() -- Yields code for roughly 8 Seconds
end
end

PickRandom(Character.Humanoid)