# Roblox Npc Ai

> Pathfinding, state machines, NPC detection (LOS/FOV), spawn systems, enemy AI patterns.

- **Type:** Skill
- **Install:** `agentstack add skill-tabooharmony-roblox-brain-roblox-npc-ai`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [TabooHarmony](https://agentstack.voostack.com/s/tabooharmony)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [TabooHarmony](https://github.com/TabooHarmony)
- **Source:** https://github.com/TabooHarmony/roblox-brain/tree/main/skills/roblox-npc-ai

## Install

```sh
agentstack add skill-tabooharmony-roblox-brain-roblox-npc-ai
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Roblox NPC & AI

Use this skill when creating NPCs, enemies, bosses, or autonomous characters that navigate, detect players, or make decisions.

## 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 end
for _, 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 end
end
```

- Connect `path.Blocked` to recompute when world changes
- Region modifiers: Anchored part + `PathfindingModifier` with 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)
- Transition func handles walk speed changes, clears target on idle

### Detection (distance → FOV → LOS)

1. **Distance** `(a-b).Magnitude` — cheapest, always first
2. **FOV** `forward:Dot(toTarget)` cosine — ~120° cone
3. **LOS** `workspace:Raycast` — expensive, last
- Skip dead players. Close-range (~30%) bypasses FOV (hearing)

### Spawners

- Track active enemies, cap count, remove on `Humanoid.Died`
- Clone → `PivotTo` → parent; `task.delay(3, Destroy)` for death anim
- Wave: `{enemies={{template, count}}, spawnDelay, waveDelay}`

### Network Ownership — MUST DO

```luau
for _, part in model:GetDescendants() do
    if part:IsA("BasePart") then part:SetNetworkOwner(nil) end
end
```
Without this, exploiters fling NPCs. Server = safe but 30Hz tick.

### Update Loop

- Throttle AI to 5-10 ticks/sec, NOT every Heartbeat
- Stagger large batches (5/frame); ALL NPC logic server-side only

### Pitfalls

- No `path.Blocked` handler → stale paths
- No `ComputeAsync` fallback → frozen NPCs
- `MoveTo` 8-sec timeout; handle `reached = false`
- Forget `SetNetworkOwner(nil)` → exploiters fling NPCs
- Dead corpses not destroyed → memory leak
- 50 NPCs pathfinding same frame → server lag spike
**Need more detail?** Load `references/full.md` for the complete reference with code examples, API tables, and edge cases.

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [TabooHarmony](https://github.com/TabooHarmony)
- **Source:** [TabooHarmony/roblox-brain](https://github.com/TabooHarmony/roblox-brain)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-tabooharmony-roblox-brain-roblox-npc-ai
- Seller: https://agentstack.voostack.com/s/tabooharmony
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
