Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. local player = game:GetService("Players").LocalPlayer
  2. local gui = player:WaitForChild("PlayerGui")
  3.  
  4. local holder = Instance.new("ScreenGui")
  5. holder.Name = "DialogHolder"
  6. holder.ResetOnSpawn = false
  7. holder.Parent = gui
  8.  
  9. local input = Instance.new("BindableEvent")
  10. local choicePicked = Instance.new("BindableEvent")
  11.  
  12. local currentDialog
  13.  
  14. local function StartConversation(conversation)
  15. if currentDialog then
  16. return
  17. end
  18. pcall(function()
  19. player.Character.Humanoid.WalkSpeed = 0
  20. end)
  21. -- sort the messages
  22. local messages = conversation:GetChildren()
  23. table.sort(messages, function(a, b) return tonumber(a.Name) < tonumber(b.Name) end)
  24. local dialogWindow = script.Dialog:Clone()
  25. dialogWindow.Parent = holder
  26. currentDialog = dialogWindow
  27. local lastChoice
  28. for i, message in next, messages do
  29. dialogWindow.HelpText.Text = ""
  30. if message:FindFirstChild("NPCName") then
  31. dialogWindow.NPC.Visible = true
  32. dialogWindow.NPC.Text = message.NPCName.Value
  33. dialogWindow.You.Visible = false
  34. else
  35. dialogWindow.NPC.Visible = false
  36. dialogWindow.You.Visible = true
  37. end
  38. local text
  39. local skip
  40. dialogWindow.Text = ""
  41. if message:FindFirstChild("Text") then
  42. text = message.Text.Value
  43. elseif message:FindFirstChild("Choice1") then
  44. for i, choice in next, message:GetChildren() do
  45. if choice.Name:sub(1, 6) == "Choice" then
  46. local button = script.Choice:Clone()
  47. button.Text = choice.Value
  48. button.LayoutOrder = choice.Name:sub(7)
  49. button.MouseButton1Click:Connect(function()
  50. lastChoice = button.LayoutOrder
  51. choicePicked:Fire(choice.Value)
  52. end)
  53. button.Parent = dialogWindow.Choices
  54. end
  55. end
  56. text = choicePicked.Event:Wait()
  57. skip = true
  58. for i, button in next, dialogWindow.Choices:GetChildren() do
  59. button:Destroy()
  60. end
  61. elseif message:FindFirstChild("Text1") then
  62. text = message["Text" .. lastChoice].Value
  63. end
  64. if not skip then
  65. local stop
  66. spawn(function()
  67. input.Event:Wait()
  68. stop = true
  69. end)
  70. for j = 1, #text do
  71. dialogWindow.Text = dialogWindow.Text .. text:sub(j, j)
  72. wait()
  73. if stop then
  74. dialogWindow.Text = text
  75. break
  76. end
  77. end
  78. dialogWindow.HelpText.Text = "Click to continue"
  79. input.Event:Wait()
  80. end
  81. end
  82. pcall(function()
  83. player.Character.Humanoid.WalkSpeed = 16
  84. end)
  85. dialogWindow:Destroy()
  86. currentDialog = nil
  87. end
  88.  
  89. game:GetService("UserInputService").InputBegan:Connect(function(i, gpe)
  90. if i.UserInputType == Enum.UserInputType.MouseButton1 then
  91. input:Fire()
  92. end
  93. end)
  94.  
  95. for i, conversation in next, game:GetService("ReplicatedStorage"):WaitForChild("Dialog"):GetChildren() do
  96. local click = Instance.new("ClickDetector")
  97. local model = conversation.Value
  98. click.MouseClick:Connect(function()
  99. StartConversation(conversation)
  100. end)
  101. click.Parent = model
  102. end
  103.  
  104. for i, conversation in next, game:GetService("ReplicatedStorage"):WaitForChild("TouchDialog"):GetChildren() do
  105. local debounce = true
  106. conversation.Value.Touched:Connect(function()
  107. if debounce then
  108. debounce = false
  109. StartConversation(conversation)
  110. wait(2)
  111. debounce = true
  112. end
  113. end)
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement