How to add a move script to NPC

so i get a script from DevForum and if i try to add a move script to npc with clone cloning is working, but npc doesnt move

	local player = Players.LocalPlayer

local success, friendPages = pcall(function()
	return Players:GetFriendsAsync(player.UserId)
end)

if not success then
	warn("There was a error while getting player's friend id!")-- remember to handle pcall errors
end

local function iterPageItems(pages)
	return coroutine.wrap(function()
		local pagenum = 1
		while true do
			for _, item in ipairs(pages:GetCurrentPage()) do
				coroutine.yield(item, pagenum)
			end
			if pages.IsFinished then
				break
			end
			pages:AdvanceToNextPageAsync()
			pagenum += 1
		end
	end)
end

local userIds = {}
for item, _pageNo in iterPageItems(friendPages) do
	table.insert(userIds, item.Id)
end

local randomFriend = userIds[math.random(1, #userIds)]
local newFriend = Players:CreateHumanoidModelFromUserId(randomFriend)
newFriend.Parent = game.Workspace
		newFriend:FindFirstChild("HumanoidRootPart").Anchored = false
		newFriend.Name = "Customer"
		local hum = workspace:FindFirstChild("Customer"):FindFirstChild("Humanoid")
1 Like

I couldn’t see where the moving NPC logic has been implemented.

??? i cant understand what you mean

So you want your NPC to move right?

Yes I want my npc moves correctly

You said that your NPC doesn’t move, so have you coded anything to your NPC to move? Because from what I can see in the code that you posted, there is no NPC moving logic at all.

this is my move code =

local Folder = game.Workspace.points
local hum = workspace:Waitforchild("Customer")

local loop = true

if loop then
	while true do
		for i, v in pairs(Folder:GetChildren()) do
			hum:MoveTo(Folder:FindFirstChild(i).Position)
			hum.MoveToFinished:Wait()
		end
	end
else
	for i, v in pairs(Folder:GetChildren()) do
		hum:MoveTo(Folder:FindFirstChild(i).Position)
		hum.MoveToFinished:Wait()
	end
end

Try this:

local waypoints = workspace.points
local hum = workspace:WaitForChild("Customer")

while true do
    for _, waypoint in pairs(waypoints:GetChildren()) do
        hum:MoveTo(waypoint.Position)
        hum.MoveToFinished:Wait()
    end
end

i tried it but that doesnt work

Can you show what is going on? The model doesn’t move or it generates errors?

nothing ever happen when i start

You’re sure the code is actually getting to that loop?