RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"npc that follows you"
-- server script local PathfindingService = game:GetService("PathfindingService") local npc = game.Workspace.NPC local followDistance = 10 while true do local players = game:GetService("Players"):GetPlayers() local closestPlayer = nil local closestDistance = math.huge for _, player in ipairs(players) do local character = player.Character if character then local distance = (npc.HumanoidRootPart.Position - character.HumanoidRootPart.Position).magnitude if distance < closestDistance then closestPlayer = character closestDistance = distance end end end if closestPlayer and closestDistance > followDistance then local path = PathfindingService:CreatePath() path:ComputeAsync(npc.HumanoidRootPart.Position, closestPlayer.HumanoidRootPart.Position) for _, waypoint in ipairs(path:GetWaypoints()) do npc.Humanoid:MoveTo(waypoint.Position) npc.Humanoid.MoveToFinished:Wait() end else npc.Humanoid:MoveTo(npc.HumanoidRootPart.Position) end wait(1) end