Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local player = game:GetService("Players").LocalPlayer
- local gui = player:WaitForChild("PlayerGui")
- local holder = Instance.new("ScreenGui")
- holder.Name = "DialogHolder"
- holder.ResetOnSpawn = false
- holder.Parent = gui
- local input = Instance.new("BindableEvent")
- local choicePicked = Instance.new("BindableEvent")
- local currentDialog
- local function StartConversation(conversation)
- if currentDialog then
- return
- end
- pcall(function()
- player.Character.Humanoid.WalkSpeed = 0
- end)
- -- sort the messages
- local messages = conversation:GetChildren()
- table.sort(messages, function(a, b) return tonumber(a.Name) < tonumber(b.Name) end)
- local dialogWindow = script.Dialog:Clone()
- dialogWindow.Parent = holder
- currentDialog = dialogWindow
- local lastChoice
- for i, message in next, messages do
- dialogWindow.HelpText.Text = ""
- if message:FindFirstChild("NPCName") then
- dialogWindow.NPC.Visible = true
- dialogWindow.NPC.Text = message.NPCName.Value
- dialogWindow.You.Visible = false
- else
- dialogWindow.NPC.Visible = false
- dialogWindow.You.Visible = true
- end
- local text
- local skip
- dialogWindow.Text = ""
- if message:FindFirstChild("Text") then
- text = message.Text.Value
- elseif message:FindFirstChild("Choice1") then
- for i, choice in next, message:GetChildren() do
- if choice.Name:sub(1, 6) == "Choice" then
- local button = script.Choice:Clone()
- button.Text = choice.Value
- button.LayoutOrder = choice.Name:sub(7)
- button.MouseButton1Click:Connect(function()
- lastChoice = button.LayoutOrder
- choicePicked:Fire(choice.Value)
- end)
- button.Parent = dialogWindow.Choices
- end
- end
- text = choicePicked.Event:Wait()
- skip = true
- for i, button in next, dialogWindow.Choices:GetChildren() do
- button:Destroy()
- end
- elseif message:FindFirstChild("Text1") then
- text = message["Text" .. lastChoice].Value
- end
- if not skip then
- local stop
- spawn(function()
- input.Event:Wait()
- stop = true
- end)
- for j = 1, #text do
- dialogWindow.Text = dialogWindow.Text .. text:sub(j, j)
- wait()
- if stop then
- dialogWindow.Text = text
- break
- end
- end
- dialogWindow.HelpText.Text = "Click to continue"
- input.Event:Wait()
- end
- end
- pcall(function()
- player.Character.Humanoid.WalkSpeed = 16
- end)
- dialogWindow:Destroy()
- currentDialog = nil
- end
- game:GetService("UserInputService").InputBegan:Connect(function(i, gpe)
- if i.UserInputType == Enum.UserInputType.MouseButton1 then
- input:Fire()
- end
- end)
- for i, conversation in next, game:GetService("ReplicatedStorage"):WaitForChild("Dialog"):GetChildren() do
- local click = Instance.new("ClickDetector")
- local model = conversation.Value
- click.MouseClick:Connect(function()
- StartConversation(conversation)
- end)
- click.Parent = model
- end
- for i, conversation in next, game:GetService("ReplicatedStorage"):WaitForChild("TouchDialog"):GetChildren() do
- local debounce = true
- conversation.Value.Touched:Connect(function()
- if debounce then
- debounce = false
- StartConversation(conversation)
- wait(2)
- debounce = true
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement