NPC won't move for some reason

Hello fellow developers! So today I tried making a moving NPC in my game, and I found this script for it. But, for some reason, this script won’t work. When I join the game, It just stays in place instead of going to the first part.

local NPC = game.Workspace.NPC.Leader

while true do
 wait(35)
 NPC.Humanoid:MoveTo(game.Workspace.Points.Point1.Position)
 NPC.Humanoid.MoveToFinished:Wait()
 wait(1)
 NPC.Humanoid:MoveTo(game.Workspace.Points.Point2.Position)
 NPC.Humanoid.MoveToFinished:Wait()
 wait(8)
 NPC.Humanoid:MoveTo(game.Workspace.Points.Point3.Position)
 NPC.Humanoid.MoveToFinished:Wait()
 wait(8)
 NPC.Humanoid:MoveTo(game.Workspace.Points.Point4.Position)
 NPC.Humanoid.MoveToFinished:Wait()
end

If anyone asks, I have four parts all named as it says in the script. Someone, please help me, I am stuck.

3 Likes

Is the “Leader” labeled as the Humanoid? What is your humanoid called?

1 Like

If that doesn’t work, then try just Move() instead of MoveTo()

Possible solutions to these:

  1. You forgot to unanchored it, the model or one of your parts
  2. You thought it doesn’t work because it literally waits 35 seconds before it moves, there is definitely nothing wrong. (Line 4)
  3. Errors occurring at the output.
1 Like

That’s not even a thing for a humanoid.

Maybe:

local NPC = game.Workspace.NPC.Leader
game.Players.PlayerAdded:Connect(function()
while true do
wait(35)
NPC.Humanoid:MoveTo(game.Workspace.Points.Point1.Position)
NPC.Humanoid.MoveToFinished:Wait()
wait(1)
NPC.Humanoid:MoveTo(game.Workspace.Points.Point2.Position)
NPC.Humanoid.MoveToFinished:Wait()
wait(8)
NPC.Humanoid:MoveTo(game.Workspace.Points.Point3.Position)
NPC.Humanoid.MoveToFinished:Wait()
wait(8)
NPC.Humanoid:MoveTo(game.Workspace.Points.Point4.Position)
NPC.Humanoid.MoveToFinished:Wait()
end
end)
local function moveTo(humanoid, targetPoint, andThen)
	local targetReached = false
	local connection
	connection = humanoid.MoveToFinished:Connect(function(reached)
		targetReached = true
		connection:Disconnect()
		connection = nil
		if andThen then
			andThen()
		end
	end)
	humanoid:MoveTo(targetPoint)
	--spawn(function()
		while not targetReached do
			if not (humanoid and humanoid.Parent) then
				break
			end
			if humanoid.WalkToPoint ~= targetPoint then
				break
			end
			humanoid:MoveTo(targetPoint)
			wait(6)
		end
		if connection then
			connection:Disconnect()
			connection = nil
		end
	--end)
end


local Points = workspace:WaitForChild("Points"):GetChildren()
local NPC = workspace.NPC.Leader
local Humanoid = NPC:WaitForChild("Humanoid")


table.sort(Points, function(a, b)
	return tonumber(a.Name:sub(6)) < tonumber(b.Name:sub(6))
end)


while true do
	for i, v in ipairs(Points) do
		moveTo(Humanoid, v.Position)
	end
	wait(35)
end

Humanoid.WalkToPoint (roblox.com)

1 Like

Yes, my Humanoid is called Leader.

I found an error at the output, which said that NPC isnt a valid member of workspace. So i made it workspace.Leader, and that worked. Thanks!

1 Like

Its a thing for humanoid, don’t simply post without checking

Move() is used on humanoids to move to a particular direction
You need to give it a Vector3 arguement

MoveTo() is used on humanois to move to a position, the humanoid move towards the position

However if you just want the humanoid to go front, you can use Move()
But if you want the humanoid to move towards a direction then use MoveTo()

I posted this post after 11 months because, many people are checking this post for help, and might get misleaded by the post you typed