Roblox Npc Ai

TabooHarmony/roblox-brain/skills/gameplay/roblox-npc-ai

by TabooHarmony38826be57ee37bcf023e9c2b85681bea3909281cNo licenseListed Oct 9, 2026Updated Oct 9, 2026

Use when creating Roblox NPCs or enemies with pathfinding, state machines, line-of-sight or FOV detection, spawns, or AI update loops.

Instructions onlySoftware Development
AI-generated overview

Guides Roblox developers in building NPC and enemy AI with pathfinding, state machines, detection and update loops.

What it does
This skill provides reference guidance for implementing Roblox NPC and enemy behavior, covering PathfindingService usage, a state machine flow from idle through patrol, chase, attack, flee and dead, and layered detection using distance, field of view and line-of-sight raycasts. It also addresses network ownership and server authority considerations and how to throttle AI update loops. It produces implementation guidance and code snippets rather than files or scripts.
When to use it
Use it when creating Roblox NPCs or enemies that need pathfinding, state machines, line-of-sight or FOV detection, spawners, or AI update loops. It is also relevant when reasoning about physics ownership or server authority for NPCs.
Requirements
No scripts are included; it is instructions only. It assumes a Roblox Studio or Roblox server environment with Luau and the Roblox APIs it references, and points to a bundled reference file for spawners, lifecycle cleanup, timeout handling and performance budgets.

Roblox NPC & AI

When to Load

Load for NPCs/enemies: pathfinding, state machines, LOS/FOV detection, spawns, AI loops, or physics ownership.

Quick Reference

PathfindingService

luau
local path = PathfindingService:CreatePath({    AgentRadius = 2, AgentHeight = 5, AgentCanJump = true,    Costs = { Water = 20, DangerZone = math.huge },})path:ComputeAsync(npcPos, targetPos)if path.Status ~= Enum.PathStatus.Success then return endfor _, wp in path:GetWaypoints() do    if wp.Action == Enum.PathWaypointAction.Jump then humanoid.Jump = true end    humanoid:MoveTo(wp.Position)    if not humanoid.MoveToFinished:Wait() then return endend
  • Recompute on blocked with a bounded retry or cancellation policy.
  • In Studio, test Workspace.PathfindingUseImprovedSearch on representative maps before rollout; it is not scriptable.
  • Avoid long requests and repeated recomputation. Moving collidable geometry can trigger navigation-mesh work.
  • Region modifiers: anchored part + PathfindingModifier Label → Costs
  • PassThrough = true for doors; PathfindingLink for disconnected navmesh
  • math.huge cost = non-traversable

State Machine

idle → patrol → chase → attack → flee → dead

  • idle/patrol → chase (player detected) → attack (in range) → idle (lost)
  • any → flee (health low) → idle (safe); any → dead (health ≤ 0)
  • Transitions own movement changes, target cleanup, and cancellation

Detection (distance → FOV → LOS)

  1. Distance (a-b).Magnitude: cheapest, always first
  2. FOV forward:Dot(toTarget) cosine; use a configured cone for your game, not a universal angle
  3. LOS workspace:Raycast: expensive, last
  • If the design includes hearing or proximity detection, make it a separate configured signal rather than a universal FOV bypass.

Network Ownership

  • Classic projects may use SetNetworkOwner(nil) for physics-sensitive NPCs, but it is not complete security. In Server Authority projects, configure the authority model instead of treating network ownership as the security boundary.

Update Loop

  • Throttle and stagger AI based on NPC count, path cost, and profiler evidence, not a universal tick rate. Keep NPC decisions and movement server-side; client code may handle presentation.

For spawners, lifecycle cleanup, timeout handling, and performance budgets, load references/full.md.

Source and attribution

Source:TabooHarmony/roblox-braininskills/gameplay/roblox-npc-aiat commit38826be

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal