Forja

Roblox NPC dialogue script

A character who talks: walk up, press the prompt and a speech bubble shows the next line. It works on computers, phones and consoles.

Where it goes

  1. 1You need a character with a part named Head. In the Avatar tab, Rig Builder makes one.
  2. 2Hover over the character's Model in the Explorer, press + and choose Script.
  3. 3Paste this in, change LINES to what your character says, and press Play.
NpcDialogue · a Script in the NPC model
-- From forja.us/tools/roblox-scripts/npc-dialogue-- Press the prompt to hear this character's next line.local LINES = {	"Hello, traveler.",	"The old mine is past the bridge.",	"Be careful down there.",}local SECONDS_SHOWN = 6local npc = script.Parentlocal head = npc:WaitForChild("Head")local bubble = Instance.new("BillboardGui")bubble.Size = UDim2.fromOffset(260, 80)bubble.StudsOffset = Vector3.new(0, 3, 0)bubble.MaxDistance = 60bubble.Enabled = falsebubble.Parent = headlocal text = Instance.new("TextLabel")text.Size = UDim2.fromScale(1, 1)text.BackgroundColor3 = Color3.new(1, 1, 1)text.TextColor3 = Color3.new(0, 0, 0)text.TextSize = 18text.TextWrapped = truetext.Font = Enum.Font.GothamMediumtext.Parent = bubblelocal prompt = Instance.new("ProximityPrompt")prompt.ActionText = "Talk"prompt.ObjectText = npc.Nameprompt.Parent = headlocal nextLine = 1local shownAt = 0prompt.Triggered:Connect(function()	text.Text = LINES[nextLine]	bubble.Enabled = true	nextLine = nextLine % #LINES + 1	local thisTime = os.clock()	shownAt = thisTime	task.wait(SECONDS_SHOWN)	if shownAt == thisTime then		bubble.Enabled = false	endend)

How it works

  • A ProximityPrompt shows the button when a player is close, with the right key or button for their device.
  • A BillboardGui keeps the speech bubble facing the camera above the head.
  • nextLine % #LINES + 1 goes back to the first line after the last one.

Make it yours

Show each player their own lines
This shows the same bubble to everyone nearby. For one player at a time, or for choices, ask the script generator.
Want something more? The script generator can write it: “A character with a dialogue box where the player picks an answer, and the character replies”

Maps to try it on: fantasy and medieval maps

Start from a finished map, and your scripts have a game to run in.

More free Roblox scripts