Загрузка данных


local npc = script.Parent
local workspace = game:GetService("Workspace")

-- Находим куртку в мире
local jacket = workspace:WaitForChild("JeremysJacket")

-- Таблица реплик пролога
local dialogueLines = {
    {speaker = "Эдан", text = "Эй, а ты не видел Джереми? Его сегодня что-то на работе нету."},
    {speaker = "Дэвид", text = "Нет, не видел. Я думал, он заболел и написал тебе, что не придет, ну или хотя бы мне написал."},
    {speaker = "Эдан", text = "Что-то здесь не чисто, может, пойдём поищем его?"},
    {speaker = "Дэвид", text = "Давай, только я сейчас закончу работу. Можешь пока город осмотреть, может, найдёшь что-нибудь."},
    {speaker = "Эдан", text = "Окей, я тогда пойду, потом к тебе приду и скажу, что нашёл."}
}

local currentLine = 1

-- Находим голову NPC
local head = npc:FindFirstChild("Head") or npc:FindFirstChild("HumanoidRootPart")

-- Удаляем старый BillboardGui, если он там был
local oldBubble = head:FindFirstChild("SpeechBubble")
if oldBubble then
    oldBubble:Destroy()
end

-- Создаем свежий BillboardGui
local speechBubble = Instance.new("BillboardGui")
speechBubble.Name = "SpeechBubble"
speechBubble.Size = UDim2.new(0, 250, 0, 70)
speechBubble.StudsOffset = Vector3.new(0, 3, 0)
speechBubble.AlwaysOnTop = false 
speechBubble.MaxDistance = 12    
speechBubble.Parent = head

local textLabel = Instance.new("TextLabel")
textLabel.Name = "TextLabel"
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.BackgroundTransparency = 1
textLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
textLabel.TextScaled = true
textLabel.TextStrokeTransparency = 0 
textLabel.Text = "Нажми, чтобы поговорить"
textLabel.Parent = speechBubble

-- Функция переключения диалога
function playDialogueStep()
    if currentLine <= #dialogueLines then
        local line = dialogueLines[currentLine]
        textLabel.Text = line.speaker .. ":\n" .. line.text
        currentLine = currentLine + 1
    else
        textLabel.Text = "Иди в город искать куртку!"
        
        -- Дэвид открывает доступ к куртке на улице
        if jacket then
            jacket.Transparency = 0 
            jacket.CanTouch = true  
        end
        
        currentLine = 1 
    end
end

-- Создаем ClickDetector для клика по NPC
local clickDetector = npc:FindFirstChildOfClass("ClickDetector")
if not clickDetector then
    clickDetector = Instance.new("ClickDetector")
    clickDetector.Parent = npc
end

clickDetector.MouseClick:Connect(function(player)
    playDialogueStep()
end)