Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I fix my NPC not moving with pathfinding?

I have this code that is supossed to spawn an enemy and then move them towards a brick in the workplace. The NPC spawns just fine but it does not move at all and just stands there. I also get no error in the output.

local PathfindingService = game:GetService("PathfindingService")

		local Enemies = game:GetService("ServerStorage"):WaitForChild("Enemies")

		local SpawnPoints = {workspace:WaitForChild("SpawnPoints").SP1,
					  workspace:WaitForChild("SpawnPoints").SP2,
					  workspace:WaitForChild("SpawnPoints").SP3}

		local EndPoints = {workspace:WaitForChild("EndPoints").EP1,
					  workspace:WaitForChild("EndPoints").EP2,
  					  workspace:WaitForChild("EndPoints").EP3}


		local ran = math.random(1,3)
	
		local RaiderClone = Enemies.Raider:Clone()
		RaiderClone.Parent = workspace
		RaiderClone.HumanoidRootPart.CFrame = SpawnPoints[ran].CFrame
	
		local path = PathfindingService:CreatePath()
		path:ComputeAsync(RaiderClone.UpperTorso.Position,workspace.EndPoints.EP1.Position)
		
		local Waypoints = path:GetWaypoints()
	
		for i,waypoint in pairs(Waypoints) do
			RaiderClone.Humanoid:MoveTo(waypoint.Position)
			RaiderClone.Humanoid.MoveToFinished:Wait(2)
		end

1 answer

✓ Accepted answer
local NPC = game.Workspace."npc name here"

while true do 
	wait()
	NPC.Humanoid:MoveTo(game.Workspace."insert part name u want the npc to go".Position)
	NPC.Humanoid.MoveToFinished:Wait()
	wait("insert time here")
	NPC.Humanoid:MoveTo(game.Workspace."insert part name u want the npc to go".Position)
	NPC.Humanoid.MoveToFinished:Wait()
	wait("instert time here")
	NPC.Humanoid:MoveTo(game.Workspace."insert part name u want the npc to go".Position)
	NPC.Humanoid.MoveToFinished:Wait()
	wait("insert time here")
end

1 comment

0

Replace local spawn points and local end points and put this instead

This discussion is preserved as it was. New answers, comments, and votes are closed.