My goal: to make the “NPC” move to Part1
I used Roblox’s tutorial on it and fixed it so it matched my layout.
Here is the code:
local NPC = game.Workspace.NPC
local humanoid = NPC.Humanoid
local Part1 = game.Workspace.Part1
local Part2 = game.Workspace.Part2
humanoid:MoveTo(Part1.Position)
humanoid:MoveTo(Part2.Position)
local PATROL_DELAY = 2
local NPC = game.Workspace.NPC
local humanoid = NPC.Humanoid
local pointA = game.Workspace.Part1
local pointB = game.Workspace.Part2
local nextDestinationObject = pointA
while wait(PATROL_DELAY) do
humanoid:MoveTo(nextDestinationObject.Position)
humanoid.MoveToFinished:Wait()
if nextDestinationObject == pointA then
nextDestinationObject = pointB
else
nextDestinationObject = pointA
end
end