File size: 3,014 Bytes
0712d5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
-- src/StarterGui/DialogueGUI.client.lua
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local player = Players.LocalPlayer
local DialogueEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("DialogueEvent")

local screenGui = Instance.new("ScreenGui")
screenGui.Name = "DialogueGUI"
screenGui.ResetOnSpawn = false
screenGui.Parent = player:WaitForChild("PlayerGui")

local mainFrame = Instance.new("Frame")
mainFrame.Name = "DialogueFrame"
mainFrame.Size = UDim2.new(0, 500, 0, 120)
mainFrame.Position = UDim2.new(0.5, -250, 1, -140)
mainFrame.BackgroundColor3 = Color3.fromRGB(20, 22, 28)
mainFrame.BackgroundTransparency = 0.1
mainFrame.BorderSizePixel = 0
mainFrame.Visible = false
mainFrame.Parent = screenGui

local corner = Instance.new("UICorner")
corner.CornerRadius = UDim.new(0, 12)
corner.Parent = mainFrame

local stroke = Instance.new("UIStroke")
stroke.Color = Color3.fromRGB(180, 160, 100)
stroke.Thickness = 2
stroke.Parent = mainFrame

local nameLabel = Instance.new("TextLabel")
nameLabel.Size = UDim2.new(0, 200, 0, 25)
nameLabel.Position = UDim2.new(0, 10, 0, 5)
nameLabel.BackgroundColor3 = Color3.fromRGB(120, 100, 50)
nameLabel.Text = "NPC"
nameLabel.TextColor3 = Color3.new(1, 1, 1)
nameLabel.TextScaled = true
nameLabel.Font = Enum.Font.GothamBold
nameLabel.Parent = mainFrame

local nameCorner = Instance.new("UICorner")
nameCorner.CornerRadius = UDim.new(0, 6)
nameCorner.Parent = nameLabel

local textLabel = Instance.new("TextLabel")
textLabel.Name = "DialogueText"
textLabel.Size = UDim2.new(1, -20, 0, 50)
textLabel.Position = UDim2.new(0, 10, 0, 35)
textLabel.BackgroundTransparency = 1
textLabel.Text = ""
textLabel.TextColor3 = Color3.fromRGB(220, 220, 220)
textLabel.TextScaled = true
textLabel.Font = Enum.Font.Gotham
textLabel.TextXAlignment = Enum.TextXAlignment.Left
textLabel.TextWrapped = true
textLabel.Parent = mainFrame

local continueLabel = Instance.new("TextLabel")
continueLabel.Size = UDim2.new(1, -10, 0, 20)
continueLabel.Position = UDim2.new(0, 5, 1, -25)
continueLabel.BackgroundTransparency = 1
continueLabel.Text = "Click NPC again to continue..."
continueLabel.TextColor3 = Color3.fromRGB(140, 140, 140)
continueLabel.TextScaled = true
continueLabel.Font = Enum.Font.Gotham
continueLabel.Parent = mainFrame

-- Typewriter effect
local function typewrite(label, text, speed)
	label.Text = ""
	for i = 1, #text do
		label.Text = string.sub(text, 1, i)
		task.wait(speed or 0.03)
	end
end

DialogueEvent.OnClientEvent:Connect(function(npcName, line, hasMore)
	nameLabel.Text = "  " .. npcName .. "  "
	mainFrame.Visible = true
	continueLabel.Text = hasMore and "Click NPC again to continue..." or "End of conversation"
	typewrite(textLabel, line, 0.025)

	if not hasMore then
		task.delay(3, function()
			mainFrame.Visible = false
		end)
	end
end)