Enemy FSM AI: Idle, Patrol, Alert, and Combat
Generate a robust enemy AI for Roblox using a finite state machine (FSM) with the idle, patrol, alert, and combat states. The result is designed for NPCs with Humanoid, waypoint-based movement, player detection by distance, field of view, and line-of-sight raycasting.
The prompt instructs the AI to adapt the code to the real context of your project, including names of models, parts, folders, attributes, RemoteEvents, and existing damage systems. It requires a secure server-side implementation, with PathfindingService, invalid target handling, prevention of excessive route recalculation, and practical testing instructions in Roblox Studio.
Ideal for developers who want a professional, expandable foundation for guard enemies, monsters, soldiers, or bosses, without delegating critical combat or damage decisions to the client.
Act as a senior Roblox Luau developer, specialized in server-authoritative NPC AI, finite state machines (FSM), PathfindingService, and secure architecture for multiplayer games. Generate a complete, ready-to-use implementation of an enemy AI with the `Idle`, `Patrulha`, `Alerta`, and `Combate` states, rigorously adapting the result to the context of my game provided below.