Skip to content

Dialogue

A conversation panel for talking with NPCs. Pair it with Lucy.DialogueTree (or snapshots sent from your server) to show the speaker’s portrait, type lines out with useReveal, and let players pick branching responses with mouse, touch, keyboard or gamepad.

Dialogue exampleDialogue example
local bb = Lucy.DialogueTree.blackboard({ name = "Alex", score = 40 })
local tree = {
	id = "club_nova",
	speaker = "dj_nova",
	entry = "hub",
	nodes = {
		hub = {
			text = "Hey {name}! Ready for tonight's set at Club Lucy?",
			choices = {
				{ id = "tips", label = "Any rhythm tips?", next = "tips", variant = "default" },
				{
					id = "vip_mix",
					label = "Spin the VIP mix",
					next = "vip",
					when = function(b)
						return (b:get("score") or 0) >= 100
					end,
					locked = "disable",
					lockedReason = "Score 100+",
				},
				{ id = "leave", label = "Catch you later", close = true },
			},
		},
		tips = { text = "Stay on the beat to keep your combo climbing.", next = "hub" },
		vip = { text = "Dropping the VIP mix now!", isEnd = true },
	},
}

local runner = Lucy.DialogueTree.new(tree, bb)
runner:start()

Lucy.Dialogue.new({
	app = app,
	runner = runner,
	instant = true,
	size = UDim2.fromOffset(620, 0),
	resolveActor = function()
		return { name = "DJ Nova", role = "Resident DJ", portrait = 1 }
	end,
	Parent = parent,
})

Chat sequence preview

When the player clicks a response, DialogueTree advances to the next node and Dialogue updates the speaker’s line, portrait and available responses in place. Linear beats without choices show a Continue link (or Leave on an end node):

Dialogue exampleDialogue example
Lucy.Stack.new({
	direction = "vertical",
	gap = "Space3",
	size = UDim2.fromOffset(620, 0),
	automaticSize = Enum.AutomaticSize.Y,
	children = {
		Lucy.Dialogue.new({
			app = app,
			speaker = "DJ Nova",
			role = "Resident DJ",
			portrait = 1,
			text = "Stay on the beat to keep your combo climbing. Ready to head back?",
			instant = true,
			canAdvance = true,
			size = UDim2.fromScale(1, 0),
		}),
		Lucy.Dialogue.new({
			app = app,
			speaker = "DJ Nova",
			role = "Resident DJ",
			portrait = 1,
			text = "Dropping the VIP mix now! See you on the dance floor.",
			variant = "overlay",
			instant = true,
			isEnd = true,
			size = UDim2.fromScale(1, 0),
		}),
	},
	Parent = parent,
})

Actor portraits

Pass resolveActor(speakerId) returning { name, role?, portrait? }. portrait accepts:

  • A Roblox Model (such as a live R15 NPC rig): cloned into a ViewportFrame and framed at head and shoulders automatically.
  • A number (UserId): rendered with Avatar.
  • An image asset string: cropped cleanly inside the portrait frame.
  • nil: falls back to a themed Avatar monogram built from the speaker’s name.

Typewriter text and cues

Lines type out using useReveal at rate characters a second (default 48). Clicking or tapping the panel while a line is typing finishes it immediately, and players with reduced motion enabled see the full line at once.

Pass onCue(snapshot) to trigger voice lines (snapshot.audio), NPC animations (snapshot.animation), mood changes (snapshot.mood), or camera angles (snapshot.meta) each time a new node is entered.

Server-authoritative conversations

For games where dialogue grants cash, items or unlocks doors, run Lucy.DialogueTree on the server against the player’s saved profile flags (Lucy.Profiles) and replicate the current Snapshot to server.me.dialogue. On the client, bind Dialogue directly to that ref:

Lucy.Dialogue.new({
	app = app,
	snapshot = app.state:ref("server.me.dialogue"),
	variant = "overlay",
	resolveActor = function(speakerId)
		return Actors.resolve(speakerId)
	end,
	onChoose = function(choiceId)
		app.server:send("dialogue.choose", choiceId)
	end,
	onAdvance = function()
		app.server:send("dialogue.advance")
	end,
	onClose = function()
		app.server:send("dialogue.close")
	end,
})

Variants and theming

Dialogue ships with three built-in variants: default, overlay and inverse. Add your own with Lucy.Dialogue.addVariant(name, rules) or override .ui-dialogue-panel, .ui-dialogue-portrait, .ui-dialogue-speaker and .ui-dialogue-text in your game’s theme.

Props

PropTypeDefaultWhat it does
runnerDialogueRunnerConnects directly to a local Lucy.DialogueTree runner
snapshotSnapshot or RefReactive snapshot (e.g. app.state:ref("server.me.dialogue"))
speakerstring or Ref""Speaker name when driving Dialogue with direct props
rolestring or RefOptional role badge shown beside the speaker’s name
portraitModel, number or stringLive rig, UserId, or image asset for the portrait
textstring or Ref""Current line of dialogue
choicestable or Ref{}List of { id, label, variant?, disabled?, lockedReason? }
variantstring"default"default, overlay, inverse or a registered variant
ratenumber48Characters per second for typewriter reveal
instantbooleanfalseSkip typewriter reveal and show text immediately
resolveActorfunction(speakerId) -> { name?, role?, portrait? }
onCuefunction(snapshot) called once each time a new node is entered
onChoosefunction(choiceId) called when the player picks an unlocked choice
onAdvancefunctionCalled when the player presses Continue on a linear node
onClosefunctionCalled when the player leaves or finishes an end node
continueTextstring"Continue"Button label on linear nodes without choices
leaveTextstring"Leave"Button label on end nodes
portraitSizenumber96Width and height of the portrait box in pixels
maxWidthnumber760Maximum panel width when size is not given