โ† Back to all scripts

NPC Typewriter Dialogue

Display NPC dialogue with a classic typewriter effect.

NPCIntermediateLocalScript in StarterPlayerScripts
npc-typewriter-dialogue.lua
-- NPC Typewriter Dialogue
local Players = game:GetService("Players")
local player  = Players.LocalPlayer
local gui     = player.PlayerGui:WaitForChild("DialogueGui")
local frame   = gui:WaitForChild("Frame")
local label   = frame:WaitForChild("TextLabel")

local DIALOGUE   = { "Hello, traveler.", "Are you looking for the lost sword?", "Be careful out there." }
local CHAR_SPEED = 0.04
local LINE_PAUSE = 2.5
local running    = false

local function typewrite(text)
    label.Text = ""
    for i = 1, #text do
        label.Text = text:sub(1, i)
        task.wait(CHAR_SPEED)
    end
end

local function runDialogue()
    if running then return end
    running = true
    frame.Visible = true
    for _, line in ipairs(DIALOGUE) do typewrite(line); task.wait(LINE_PAUSE) end
    frame.Visible = false
    running = false
end
Related scripts in NPC
NPC Wander (Pathfinding)Intermediate โ†’
Something broken or not working?
๐Ÿ”ง Try the AI Script Fixer โ†’