Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local dialogue = {}
- local TweenService = game:GetService("TweenService")
- local tweenInfo = TweenInfo.new(0.3)
- function dialogue.Show(gui: ScreenGui)
- gui.Enabled = true
- for i,v in gui:GetDescendants() do
- if v.BackgroundTransparency and not v:IsA("TextLabel") and v.Name ~= "ChoiceContainer" then
- v.BackgroundTransparency = 1
- local tween = TweenService:Create(v, tweenInfo, { BackgroundTransparency = 0 })
- tween:Play()
- end
- end
- end
- function dialogue.Hide(gui: ScreenGui)
- for i,v in gui:GetDescendants() do
- if v.BackgroundTransparency and not v:IsA("TextLabel") and v.Name ~= "ChoiceContainer" then
- v.BackgroundTransparency = 0
- local tween = TweenService:Create(v, tweenInfo, { BackgroundTransparency = 1 })
- tween:Play()
- end
- end
- gui.Enabled = false
- end
- function dialogue.Say(gui: ScreenGui, info, plr)
- local speaker = gui.DialogueContainer.Speaker
- local text: TextLabel = gui.DialogueContainer.Speech
- local choice1: TextButton = gui.ChoiceContainer.Choice1
- local choice2: TextButton = gui.ChoiceContainer.Choice2
- speaker.Text = info["Speaker"]
- text.Text = info["Speech"]
- choice1.Text = info["First"]
- choice2.Text = info["Second"]
- choice1.Visible = false
- choice2.Visible = false
- for i = 0 ,utf8.len(text.Text), 1 do
- text.MaxVisibleGraphemes = i
- local sfx = game.SoundService.Typewriter:Clone()
- sfx.Parent = plr.Character
- sfx:Destroy()
- if string.sub(text.Text, i , i) == "!" or string.sub(text.Text, i , i) == "." then
- task.wait(1)
- elseif string.sub(text.Text, i , i) == "," then
- task.wait(0.5)
- end
- task.wait(0.05)
- end
- choice1.Visible = true
- choice2.Visible = true
- choice1.MouseButton1Click:Connect(function()
- choice1.Visible = false
- choice2.Visible = false
- text.Text = info["FirstResponse"]
- for i = 0 ,utf8.len(text.Text), 1 do
- text.MaxVisibleGraphemes = i
- local sfx = game.SoundService.Typewriter:Clone()
- sfx.Parent = plr.Character
- sfx:Destroy()
- if string.sub(text.Text, i , i) == "!" or string.sub(text.Text, i , i) == "." then
- task.wait(1)
- elseif string.sub(text.Text, i , i) == "," then
- task.wait(0.5)
- end
- task.wait(0.05)
- end
- dialogue.Hide(gui)
- end)
- choice2.MouseButton1Click:Connect(function()
- choice1.Visible = false
- choice2.Visible = false
- text.Text = info["SecondResponse"]
- for i = 0 ,utf8.len(text.Text), 1 do
- text.MaxVisibleGraphemes = i
- local sfx = game.SoundService.Typewriter:Clone()
- sfx.Parent = plr.Character
- sfx:Destroy()
- if string.sub(text.Text, i , i) == "!" or string.sub(text.Text, i , i) == "." then
- task.wait(1)
- elseif string.sub(text.Text, i , i) == "," then
- task.wait(0.5)
- end
- task.wait(0.05)
- end
- dialogue.Hide(gui)
- end)
- end
- return dialogue
Add Comment
Please, Sign In to add comment