Ultimate_69

Dialoge Module

Feb 6th, 2025
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. local dialogue = {}
  2.  
  3. local TweenService = game:GetService("TweenService")
  4. local tweenInfo = TweenInfo.new(0.3)
  5.  
  6. function dialogue.Show(gui: ScreenGui)
  7. gui.Enabled = true
  8.  
  9. for i,v in gui:GetDescendants() do
  10. if v.BackgroundTransparency and not v:IsA("TextLabel") and v.Name ~= "ChoiceContainer" then
  11. v.BackgroundTransparency = 1
  12. local tween = TweenService:Create(v, tweenInfo, { BackgroundTransparency = 0 })
  13. tween:Play()
  14. end
  15. end
  16. end
  17.  
  18. function dialogue.Hide(gui: ScreenGui)
  19. for i,v in gui:GetDescendants() do
  20. if v.BackgroundTransparency and not v:IsA("TextLabel") and v.Name ~= "ChoiceContainer" then
  21. v.BackgroundTransparency = 0
  22. local tween = TweenService:Create(v, tweenInfo, { BackgroundTransparency = 1 })
  23. tween:Play()
  24. end
  25. end
  26.  
  27. gui.Enabled = false
  28. end
  29.  
  30.  
  31. function dialogue.Say(gui: ScreenGui, info, plr)
  32. local speaker = gui.DialogueContainer.Speaker
  33. local text: TextLabel = gui.DialogueContainer.Speech
  34. local choice1: TextButton = gui.ChoiceContainer.Choice1
  35. local choice2: TextButton = gui.ChoiceContainer.Choice2
  36.  
  37. speaker.Text = info["Speaker"]
  38. text.Text = info["Speech"]
  39. choice1.Text = info["First"]
  40. choice2.Text = info["Second"]
  41.  
  42. choice1.Visible = false
  43. choice2.Visible = false
  44.  
  45. for i = 0 ,utf8.len(text.Text), 1 do
  46. text.MaxVisibleGraphemes = i
  47. local sfx = game.SoundService.Typewriter:Clone()
  48. sfx.Parent = plr.Character
  49. sfx:Destroy()
  50. if string.sub(text.Text, i , i) == "!" or string.sub(text.Text, i , i) == "." then
  51. task.wait(1)
  52. elseif string.sub(text.Text, i , i) == "," then
  53. task.wait(0.5)
  54. end
  55. task.wait(0.05)
  56. end
  57.  
  58. choice1.Visible = true
  59. choice2.Visible = true
  60.  
  61. choice1.MouseButton1Click:Connect(function()
  62. choice1.Visible = false
  63. choice2.Visible = false
  64.  
  65. text.Text = info["FirstResponse"]
  66.  
  67. for i = 0 ,utf8.len(text.Text), 1 do
  68. text.MaxVisibleGraphemes = i
  69. local sfx = game.SoundService.Typewriter:Clone()
  70. sfx.Parent = plr.Character
  71. sfx:Destroy()
  72. if string.sub(text.Text, i , i) == "!" or string.sub(text.Text, i , i) == "." then
  73. task.wait(1)
  74. elseif string.sub(text.Text, i , i) == "," then
  75. task.wait(0.5)
  76. end
  77. task.wait(0.05)
  78. end
  79.  
  80. dialogue.Hide(gui)
  81. end)
  82.  
  83. choice2.MouseButton1Click:Connect(function()
  84. choice1.Visible = false
  85. choice2.Visible = false
  86.  
  87. text.Text = info["SecondResponse"]
  88.  
  89. for i = 0 ,utf8.len(text.Text), 1 do
  90. text.MaxVisibleGraphemes = i
  91. local sfx = game.SoundService.Typewriter:Clone()
  92. sfx.Parent = plr.Character
  93. sfx:Destroy()
  94. if string.sub(text.Text, i , i) == "!" or string.sub(text.Text, i , i) == "." then
  95. task.wait(1)
  96. elseif string.sub(text.Text, i , i) == "," then
  97. task.wait(0.5)
  98. end
  99. task.wait(0.05)
  100. end
  101.  
  102. dialogue.Hide(gui)
  103. end)
  104.  
  105. end
  106.  
  107.  
  108. return dialogue
  109.  
Add Comment
Please, Sign In to add comment