Goal - A GOAP (Goal-Oriented Action Planning) System for Roblox

⚠️ This framework is deprecated!

Goal v1.5.0 | GOAP AI for Roblox NPCs

📁 GitHub | 📦 Wally | 📚 API Docs | 📝 Changelog

A GOAP (Goal-Oriented Action Planning) library for building adaptive NPC behavior in Roblox. Instead of scripting exact behavior sequences, you define what NPCs can do and what they want - they figure out how to achieve their goals on their own.

"After searching for a proper GOAP implementation for Roblox and finding nothing, I built one myself."

Currently used in production for combat AI, survival systems, and squad tactics.


The Problem

Traditional NPC AI with behavior trees or conditional chains:

  • Requires manual rewiring for every new behavior
  • Edge cases multiply exponentially
  • Results in predictable, scripted-feeling NPCs
  • Becomes increasingly difficult to maintain

The Solution

GOAP works differently. You define:

  1. Available actions (what NPCs can do)
  2. Goals (what NPCs want to achieve)
  3. World state (current situation)

The planner automatically finds the optimal sequence of actions to achieve the goal.

Behavior Trees GOAP
Manually define all transitions AI generates action sequences
New behavior breaks existing logic Add actions without touching existing code
Rigid, predetermined responses Dynamic adaptation to situations
"If hungry AND near food AND not in combat..." "Goal: not hungry. Action available: eat food"

Benefits

  • NPCs adapt to situations dynamically
  • Add new behaviors without breaking existing ones
  • Emergent behavior from simple rules
  • Less code to maintain
  • Handles hundreds of NPCs efficiently

Example

local Goal = require(path.to.Goal)
local planner = Goal.Planner.new()

-- Define available actions
local gatherWood = Goal.Action.new({
    name = "GatherWood",
    cost = 2,
    preconditions = {},
    effects = { hasWood = true },
})

local makeFire = Goal.Action.new({
    name = "MakeFire", 
    cost = 1,
    preconditions = { hasWood = true },
    effects = { hasFire = true },
})

planner:registerActions({ gatherWood, makeFire })

-- Define objective
local warmthGoal = Goal.Goal.new({
    name = "GetWarm",
    desiredState = { hasFire = true },
    priority = 1,
})

-- Generate plan
local plan = planner:plan(worldState, warmthGoal)
-- Returns: GatherWood → MakeFire

The NPC doesn't have "gather wood then make fire" hardcoded. It discovers this sequence by understanding that making fire requires wood, which it can get by gathering.


Use Cases

Combat AI - Tactical enemies that flank when outnumbered, retreat at low health, call for backup, and use cover

Stealth Systems - Guards that patrol routes, investigate sounds, alert nearby units, and remember player positions

Town NPCs - Characters with daily routines that adapt based on needs (hunger, fatigue, work schedules)

Squad Coordination - Teams that avoid duplicate targeting, provide covering fire, revive allies, and coordinate flanking

Boss AI - Multi-phase encounters that adapt tactics based on health, summon reinforcements, and reposition strategically

Survival NPCs - Characters that prioritize competing needs (hunger, thirst, warmth, safety) and plan multi-step solutions


Installation

Via Wally

[dependencies]
goal = "aliboily/goal@1.5.0"

Then: wally install

Via GitHub

Download from releases and place in ReplicatedStorage.Packages.Goal


Quick Start

local Goal = require(ReplicatedStorage.Packages.goal)
local planner = Goal.Planner.new()

-- Define what the NPC can do
local patrol = Goal.Action.new({
    name = "Patrol",
    cost = 1,
    preconditions = { alert = false },
    effects = { patrolling = true },
})

-- Define what the NPC wants
local defendArea = Goal.Goal.new({
    name = "DefendArea",
    desiredState = { areaSecure = true },
    priority = 5,
})

-- Generate and execute plan
local worldState = { alert = false, enemySpotted = false }
local plan = planner:plan(worldState, defendArea)

if plan then
    for _, action in ipairs(plan) do
        action:execute()
    end
end

See main_example.server.lua for a complete implementation with 800 NPCs.


Features

  • GOAP Planner - A* pathfinding, dynamic cost calculation, plan caching, interrupt handling
  • Navigation - Grid pathfinding, cover evaluation, flanking routes, high ground calculation, escape paths
  • Perception - Vision cones, hearing radius, awareness states, memory integration
  • Personality Traits - 8 configurable traits (aggression, caution, etc.), 8 preset profiles, mood system
  • Utility System - 10 evaluation curves, multi-factor decision making
  • Memory - Short-term, episodic, and long-term memory with pattern recognition
  • Shared Knowledge - Blackboard system for squad coordination and target management
  • Parallel Processing - Actor-based execution, tick budgeting, frame distribution
  • Production Features - Cooldown system, resource costs, state persistence, debug logging

Performance

  • Handles 800+ concurrent NPCs
  • Configurable frame budget (default 4ms)
  • Object pooling for memory efficiency
  • Parallel execution support
  • Spatial grid for fast proximity queries

Contributing

This is an open-source project. Bug reports, feature requests, and pull requests are welcome on GitHub.


License

MIT - Free for commercial and personal use.


Links

27 Likes

Example link is invalid..

characters limit

Yeah my fault I’ve updated it, should work now

No way I was just making one of these recently, I never thought anyone gonna be making one of these anytime soon. These implementation looked way better than what I could’ve made myself, this is pretty interesting.

1 Like

hey so is there a way to get a .rbxm file without rojo

1 Like

this is incredible, amazing work!

I really appreciate truly useful and mindful resources like this. A big issue with a lot of Roblox games is very flat/dumb NPC’s that can very easily make an otherwise great game fall flat on its face.

This is extremely cool, I have been using the Navigation, is there any way to make it jump over obstacles and climb trusses?

Jumping is supported through the PathfindingAdapter module. It uses Roblox’s PathfindingService which handles jump waypoints automatically. This is enabled by default (agentCanJump = true).

Climbing can be enabled by configuring the PathfindingAdapter:

local pathfinder = PathfindingAdapter.new({
    agentCanClimb = true,
})

This leverages Roblox’s native climbing support for trusses and ladders.

Note that the tactical Navigation module (used for cover, flanking, etc.) is ground-based only. If you need NPCs to jump gaps or climb structures, use PathfindingAdapter for movement and Navigation for tactical decisions like finding cover positions.

1 Like

This is awesome resrource. But us noobs(the beginners who dont know a lot about scripting) dont know how to manipulate it and use it entirely.

Main question is how do i connect it to movement function?
for example for

local gatherWood = Goal.Action.new({
    name = "GatherWood",
    cost = 2,
    preconditions = {},
    effects = { hasWood = true },
})

How does it know where the wood is? where do i place the target wood part position or where do i use that in the script?

The example folder with 800 npcs they all chase me and they dont run when i deal damage to them. they either chase or patrol. I dont understand this example or how to make it work

The example was purely just to show performance with that many NPCs, I didn’t program the behaviors to operate. They are aware of it happening they just don’t have a programmed behavior / response to take cover.

Boss i have an issue here:

local Goal = require(script.goal)
local planner = Goal.Planner.new()
local NPC = workspace.NPC -- your NPC model
local worldState = {
	hasWood = false,
	hasFire = false,
}
-- Define what your NPC can do
local gatherWood = Goal.Action.new({
	name = "GatherWood",
	cost = 2,
	preconditions = {},
	effects = { hasWood = true },
	executeFn = function()
		local woodPart = workspace:FindFirstChild("Wood")
		if woodPart then
			NPC.Humanoid:MoveTo(woodPart.Position)
		end
		return true
	end,
})

local makeFire = Goal.Action.new({
	name = "MakeFire", 
	cost = 1,
	preconditions = { hasWood = true },
	effects = { hasFire = true },
	executeFn = function()
		local campfire = workspace:FindFirstChild("Campfire")
		if campfire then
			NPC.Humanoid:MoveTo(campfire.Position)
		end
		return true
	end
})

planner:registerActions({ gatherWood, makeFire })

-- Define what your NPC wants
local warmthGoal = Goal.Goal.new({
	name = "GetWarm",
	desiredState = { hasFire = true },
	priority = 1,
})

-- Let the AI figure it out
local plan = planner:plan(worldState, warmthGoal)
-- Result: GatherWood → MakeFire ✨

i keep getting this error:
Workspace.Script.goal.Planner:477: attempt to call missing method ‘satisfies’ of table - Server - Planner:477
Stack Begin - Studio
13:36:39.072 Script ‘Workspace.Script.goal.Planner’, Line 477 - function plan - Studio - Planner:477
13:36:39.072 Script ‘Workspace.Script’, Line 47 - Studio - Script:47
13:36:39.072 Stack End - Studio

What am i missing or doing wrong?

The issue is that worldState needs to be a Goal.State object, not a plain table. The planner calls :satisfies() which only exists on State objects.

Fix:

-- Change this:
local worldState = {
    hasWood = false,
    hasFire = false,
}

-- To this:
local worldState = Goal.State.new({
    hasWood = false,
    hasFire = false,
})

Goal.State wraps your data and provides methods like :satisfies(), :get(), :set() that the planner needs internally.

1 Like

Boss my NPC doesnt move at all but i get no errors. What causes it? and how do i print the results?

When are the GitHub Links going to be fixed? I really want to use this for my games as this is probably the perfect module for what I want to make

4 Likes

Hey, what happened to the github link why doesn’t it work i would really like to try this system