DEV Community

Korvus
Korvus

Posted on

Add AI-powered talking NPCs to your Roblox game (one server request)

Static dialogue trees get old the second a player types something you
didn't predict. Here's how to give any Roblox NPC a real brain — one that
answers in character to whatever the player actually writes — with a
single server-side request.

## The idea

If you put an API key in a LocalScript, it ships to every player and
gets scraped in minutes. Every AI call must go from a server Script,
and you must enable Game Settings → Security → Allow HTTP Requests.

## One request


lua
  local HttpService = game:GetService("HttpService")

  local function ask(personality, playerMessage)
      local body = HttpService:JSONEncode({ system = personality, text =
  playerMessage })
      local res = HttpService:PostAsync("YOUR_AI_ENDPOINT", body)
      return HttpService:JSONDecode(res).text
  end

  print(ask("You are a gruff dwarven blacksmith. One short in-character
  line.",
            "can you forge me a sword?"))
  --> "Aye — hand over the ore and I'll hammer ye a blade."

  Swap the personality string and you have a merchant who haggles, a guard
  who warns you off, a priest who blesses you.

  Paying for it without a credit card

  Roblox devs earn Robux, not dollars, and plenty don't have a card to hand
  to OpenAI. So I built Cortex (https://cortex-rbx.github.io) — the same
  one-request idea, but you pay in Robux, the key stays server-side, and
  you're billed on output tokens only (the system prompt, memory and
  history you resend every call are free, and repeated lines are cached
  free — NPCs say a lot of similar things).

  local Cortex = require(game.ServerStorage.Cortex)
  local ai = Cortex.new("YOUR_KEY")
  print(ai:ask("You are a gruff blacksmith. One short line.", "forge me a
  sword?"))

  It's not just dialogue

  - Adaptive quests tuned to the player's level and story
  - Item names, descriptions and lore generated once and cached
  - Chat moderation by meaning (SAFE / BLOCK) — catches intent word-lists
  miss
  - An in-game assistant that explains a mechanic in words that fit the
  moment

  Try it

  - Live demo (a real model, not a scripted reply):
  https://cortex-rbx.github.io
  - Free open-source kit: https://github.com/cortex-rbx/roblox-ai-kit
  - Free beta key: https://discord.gg/A3MSqwkvn7

  Open beta, free right now. Would love feedback on the API and what you'd
  want your NPCs to say.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)