RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"npc that follows the player"
-- server script local PathfindingService = game:GetService("PathfindingService") local npc = game.Workspace.NPC local followDistance = 10 while true do for _, player in ipairs(game.Players:GetPlayers()) do if player.Character then local playerPosition = player.Character.HumanoidRootPart.Position local npcPosition = npc.HumanoidRootPart.Position local distance = (playerPosition - npcPosition).magnitude if distance <= followDistance then local path = PathfindingService:CreatePath() path:ComputeAsync(npcPosition, playerPosition) for _, waypoint in pairs(path:GetWaypoints()) do npc.Humanoid:MoveTo(waypoint.Position) npc.Humanoid.MoveToFinished:Wait() end end end end wait(1) end