I need help where when the NPC is following you it spawns in 2 nodes where then it makes the NPC slower and makes him look to the right and forward again.
Video:
https://gyazo.com/4024f2f151c0db83236aa09828c525a6
Code:
while wait() do
if config.owner.Value ~= nil then
local pathParams = {
["AgentHeight"] = 6,
["AgentRadius"] = 6,
["AgentCanJump"] = true
}
local path = pathfindingService:CreatePath(pathParams)
local playerCharacter = config.owner.Value.Character
local distance1 = (NPC.PrimaryPart.Position - playerCharacter.PrimaryPart.Position).magnitude
if playerCharacter and distance1 > 10 then
path:ComputeAsync(NPC.HumanoidRootPart.Position, playerCharacter.PrimaryPart.Position)
local waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
local part = Instance.new("Part", workspace)
part.Shape = Enum.PartType.Ball
part.BrickColor = BrickColor.White()
part.Material = Enum.Material.Neon
part.CanCollide = false
part.Anchored = true
part.Size = Vector3.new(.5,.5,.5)
part.Locked = true
part.Position = waypoint.Position
game:GetService("Debris"):AddItem(part, 1)
if waypoint.Action == Enum.PathWaypointAction.Jump then
NPC.Humanoid.Jump = true
end
NPC.Humanoid:MoveTo(waypoint.Position)
while wait() do
local distance = (NPC.PrimaryPart.Position - waypoint.Position).Magnitude
local distance_from_player = (NPC.PrimaryPart.Position - playerCharacter.PrimaryPart.Position).Magnitude
if distance < 5 then
break
end
if distance_from_player < 10 then
NPC.Humanoid:MoveTo((NPC.PrimaryPart.CFrame*CFrame.new(0,0,-3)).p)
break
end
end
end
end
end
end