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


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

local jacket = workspace:FindFirstChild("JeremysJacket")

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

local currentLine = 1

local head = npc:FindFirstChild("Head") or npc:FindFirstChild("HumanoidRootPart")
if not head then return end

local oldBubble = head:FindFirstChild("SpeechBubble")
if oldBubble then
    oldBubble:Destroy()
end

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

local function playDialogueStep()
    if currentLine <= #dialogueLines then
        local line = dialogueLines[currentLine]
        textLabel.Text = line.speaker .. ":\n" .. line.text
        currentLine = currentLine + 1
    else
        textLabel.Text = "Иди в город искать куртку!"
        
        local targetJacket = workspace:FindFirstChild("JeremysJacket")
        if targetJacket then
            targetJacket.Transparency = 0 
            targetJacket.CanTouch = true  
        end
        
        currentLine = 1 
    end
end

local clickDetector = npc:FindFirstChildOfClass("ClickDetector")
if not clickDetector then
    clickDetector = Instance.new("ClickDetector")
    clickDetector.Parent = npc
end

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