RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"npc that follows you"
-- server script local PathfindingService = game:GetService("PathfindingService") local npc = game.Workspace.NPC local followRadius = 10 while true do local closestPlayer = nil local closestDistance = math.huge for _, player in ipairs(game.Players:GetPlayers()) do if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then local distance = (npc.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).magnitude if distance < closestDistance then closestPlayer = player closestDistance = distance end end end if closestPlayer and closestDistance <= followRadius then local path = PathfindingService:CreatePath() path:ComputeAsync(npc.HumanoidRootPart.Position, closestPlayer.Character.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