Was wondering how I can make an NPC (dummy) walk from one point to another, and then back an infinite amount of times. Thanks!
:MoveTo
, is a primary function of the Humanoid, it's purpose is to move the player.
local Player_Name = "Hillary" game.Workspace[Player_Name].Humanoid:MoveTo(workspace.Part)
1st parameter; Position, this concludes where we want to move the player to, so in the code above me, we moved the player to the part.
This would move the player infinitely between the two points you mentioned;
local NPCName = "Max" -- the name of your npc local Point_A_Name = "PointA" -- the name of the first place you want to move him to local Point_B_Name = "PointB" function Move(place) game.Workspace[NPCName].Humanoid:MoveTo(place) game.Workspace[NPCName].Humanoid.MoveToFinished:Wait() end while wait() do Move(game.Workspace[Point_B_Name].Position) Move(game.Workspace[Point_A_Name].Position) end
Aha! There you go.
:MoveToFinished, waits until the player has moved to the specific point.
Let's say the path between the two points are very hard to get to, well in this case the NPC has no brain so it would walk straight into the wall if there was a hard path.
So we use PathFinding!;
local NPCName = "Max" local Point_A_Name = "PointA" local Point_B_Name = "PointB" local PathFindingService = game:GetService("PathfindingService") workspace[NPCName].HumanoidRootPart:SetNetworkOwner(nil) function PathFind(place) local Path = PathFindingService:CreatePath() Path:ComputeAsync(workspace[NPCName].Torso.Position, place) local WayPoints = Path:GetWaypoints() for i, waypoint in pairs(WayPoints) do if waypoint.Action == Enum.PathWaypointAction.Jump then workspace[NPCName].Humanoid:ChangeState(Enum.HumanoidStateType.Jumping) end workspace[NPCName].Humanoid:MoveTo(waypoint.Position) workspace[NPCName].Humanoid.MoveToFinished:Wait() end end while wait() do PathFind(game.Workspace[Point_B_Name].Position) PathFind(game.Workspace[Point_A_Name].Position) end
you can use a mixture of a For
loop and Pathfinding Service