-- // DialoguesModule // ModuleScript
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")
local player = [Link]
local Camera = [Link]
local dialogues = {}
local DefaultDialogueFrame = [Link]
local DefaultDialogueText = [Link]
local DefaultContinueButton = [Link]
local DefaultDialogueTitle = [Link]
local DefaultDialogueReplies = [Link]
local DefaultDialogueIcon = DefaultDialogueFrame:FindFirstChild("DialogueIcon")
local DialogueFrame = DefaultDialogueFrame
local DialogueText = DefaultDialogueText
local ContinueButton = DefaultContinueButton
local DialogueTitle = DefaultDialogueTitle
local DialogueReplies = DefaultDialogueReplies
local DialogueIcon = DefaultDialogueIcon
local CinematicBar1 = [Link]:FindFirstChild("CinematicBar1")
local CinematicBar2 = [Link]:FindFirstChild("CinematicBar2")
local TypewriterSound = [Link]:FindFirstChild("TypewriterSound")
local BackgroundSound = [Link]:FindFirstChild("BackgroundSound")
local ContentSound = [Link]:FindFirstChild("ContentSound")
local DefaultReplyFrame = [Link]
local ReplyFrame = DefaultReplyFrame
local currentDialogue = nil
local currentLayer = nil
local dialogueIndex = 1
local typewriterCoroutine = nil
local isTyping = false
local dialogueActive = false
local autoScrollCoroutine = nil
local stopAutoScroll = false
local MainTweenInfo = [Link](0.5, [Link],
[Link])
local initialUIStrokeTransparency = {}
local originalWalkSpeed = nil -- We will set this when the dialogue starts
local ContinueButtonConnection = nil
local humanoidDiedConnection = nil -- Connection for [Link] event
local characterAddedConnection = nil -- Connection for CharacterAdded event
local function storeInitialUIStrokeTransparency(elements)
initialUIStrokeTransparency = {}
for _, element in ipairs(elements) do
local uiStroke = element:FindFirstChildOfClass("UIStroke")
if uiStroke then
initialUIStrokeTransparency[element] = [Link]
end
end
end
local elements = {
[Link],
[Link],
[Link],
[Link],
}
storeInitialUIStrokeTransparency(elements)
function disableReplyButtons()
for _, descendant in ipairs(DialogueReplies:GetDescendants()) do
if descendant:IsA("TextButton") then
[Link] = false
end
end
end
function executeLayerFunctions(contentIndex, replyName)
if [Link] then
for _, func in pairs([Link]) do
if (replyName and [Link] == replyName) or (not
replyName and [Link] == contentIndex) then
if [Link] then
[Link]()
else
warn("Function not defined for ExecuteContent:",
[Link])
end
end
end
end
end
function [Link](replyInfo)
local replyClone = ReplyFrame:Clone()
[Link] = [Link] or "ReplyClone"
[Link] = [Link]
[Link].MouseButton1Click:Connect(function()
disableReplyButtons()
-- Execute functions related to this reply before ending the dialogue
if ReplyLayer is nil
if not [Link] then
[Link]() -- End dialogue first
end
executeLayerFunctions(nil, [Link])
if [Link] then
currentLayer = currentDialogue[[Link]]
dialogueIndex = 1
local tweenOutReplies = TweenService:Create(DialogueReplies,
MainTweenInfo, {GroupTransparency = 1})
tweenOutReplies:Play()
[Link]:Connect(function()
for _, child in ipairs(DialogueReplies:GetChildren()) do
if child:IsA("Frame") then
child:Destroy()
end
end
[Link]()
if [Link] > 0 then
startAutoScroll()
end
end)
else
[Link]()
end
end)
return replyClone
end
function [Link](replies)
for _, reply in ipairs(replies) do
local replyFrame = [Link](reply)
[Link] = DialogueReplies
end
local tweenInReplies = TweenService:Create(DialogueReplies, MainTweenInfo,
{GroupTransparency = 0})
tweenInReplies:Play()
if not [Link] then
tweenContinueButtonTransparency(1)
[Link] = false
[Link] = false -- Make sure it's not clickable
else
tweenContinueButtonTransparency(0)
[Link] = false
[Link] = false
end
stopAutoScroll = true
end
function playTypewriterSound()
if TypewriterSound and [Link] then
[Link] = [Link]
if [Link] then
[Link] = [Link](80, 120) / 100
else
[Link] =
[Link] or 1
end
TypewriterSound:Play()
end
end
function playContentSound(index)
if ContentSound and [Link] and
[Link][index] then
local soundId = [Link][index]
if soundId then
[Link] = "rbxassetid://" .. tostring(soundId)
ContentSound:Play()
end
end
end
function updateDialogueIcon()
if DialogueIcon and [Link] then
[Link] = [Link]
end
end
function updateDialogueTitle()
if [Link] then
[Link] = [Link]
else
[Link] = [Link]
end
end
function tweenContinueButtonTransparency(targetTransparency)
local tween = TweenService:Create([Link], MainTweenInfo,
{GroupTransparency = targetTransparency})
tween:Play()
local uiStroke = [Link]:FindFirstChildOfClass("UIStroke")
if uiStroke then
local initialTransparency =
initialUIStrokeTransparency[[Link]] or 0
local targetUIStrokeTransparency = targetTransparency == 1 and 1 or
initialTransparency
TweenService:Create(uiStroke, MainTweenInfo, {Transparency =
targetUIStrokeTransparency}):Play()
end
end
function [Link](text, typewriterSpeed, specialTypewriterSpeed)
[Link] = ""
isTyping = true
for i = 1, #text do
if not isTyping then
[Link] = text
break
end
[Link] = text:sub(1, i)
local char = text:sub(i, i)
local speed = typewriterSpeed
if i < #text and char:match("[%.,:;%[%]{}!?]") then
speed = specialTypewriterSpeed
end
playTypewriterSound()
wait(speed)
end
isTyping = false
local isLastPieceOfContent = not [Link][dialogueIndex]
if [Link] and #[Link] > 0 and
isLastPieceOfContent then
[Link]([Link])
end
if [Link] and not
[Link] then
tweenContinueButtonTransparency(0)
[Link] = true
[Link] = true -- Ensure it's clickable
end
if isLastPieceOfContent and [Link] and #[Link] >
0 then
if not [Link] then
tweenContinueButtonTransparency(1)
[Link] = false
[Link] = false
else
tweenContinueButtonTransparency(0)
[Link] = false
[Link] = false
end
end
if [Link] > 0 and not [Link] then
startAutoScroll()
end
end
function [Link]()
if [Link][dialogueIndex] then
local text = [Link][dialogueIndex]
playContentSound(dialogueIndex)
dialogueIndex = dialogueIndex + 1
updateDialogueIcon()
updateDialogueTitle()
executeLayerFunctions(dialogueIndex - 1)
if typewriterCoroutine and [Link](typewriterCoroutine) ==
"suspended" then
[Link](typewriterCoroutine)
end
typewriterCoroutine = [Link](function()
if [Link] then
[Link](text,
[Link],
[Link])
else
[Link] = text
isTyping = false
local isLastPieceOfContent = not
[Link][dialogueIndex]
if isLastPieceOfContent and [Link] and
#[Link] > 0 then
if not
[Link] then
tweenContinueButtonTransparency(1)
[Link] = false
[Link] = false
else
tweenContinueButtonTransparency(0)
[Link] = false
[Link] = false
end
else
tweenContinueButtonTransparency(0)
[Link] = true
[Link] = true
end
end
end)
[Link](typewriterCoroutine)
if [Link] and not
[Link] then
tweenContinueButtonTransparency(1)
[Link] = false
[Link] = false
else
[Link] = true -- Ensure it's clickable
end
else
if [Link] and #[Link] > 0 then
[Link]([Link])
if not [Link]
then
tweenContinueButtonTransparency(1)
[Link] = false
[Link] = false
else
tweenContinueButtonTransparency(0)
[Link] = false
[Link] = false
end
else
[Link]()
end
end
end
function [Link]()
disableReplyButtons()
[Link] = false
[Link] = false
stopAutoScroll = true
local tweenOutFrame = TweenService:Create(DialogueFrame, MainTweenInfo,
{Position = [Link](0.5, 0, 0.6, 0)})
local tweens = {}
for _, element in ipairs(elements) do
[Link](tweens, TweenService:Create(element, MainTweenInfo,
{GroupTransparency = 1}))
local uiStroke = element:FindFirstChildOfClass("UIStroke")
if uiStroke then
[Link](tweens, TweenService:Create(uiStroke, MainTweenInfo,
{Transparency = 1}))
end
end
[Link](tweens, TweenService:Create(DialogueReplies, MainTweenInfo,
{GroupTransparency = 1}))
tweenOutFrame:Play()
for _, tween in ipairs(tweens) do
tween:Play()
end
if [Link] then
local tweenOutBar1 = TweenService:Create(CinematicBar1, MainTweenInfo,
{Position = [Link](0.5, 0, -0.2, 0)})
local tweenOutBar2 = TweenService:Create(CinematicBar2, MainTweenInfo,
{Position = [Link](0.5, 0, 1.2, 0)})
tweenOutBar1:Play()
tweenOutBar2:Play()
end
if [Link] then
local tweenOutBackgroundSound = TweenService:Create(BackgroundSound,
MainTweenInfo, {Volume = 0})
tweenOutBackgroundSound:Play()
[Link]:Connect(function()
BackgroundSound:Stop()
end)
end
[Link]:Connect(function()
[Link] = ""
[Link] = ""
[Link] = false
for _, element in ipairs(elements) do
local uiStroke = element:FindFirstChildOfClass("UIStroke")
if uiStroke and initialUIStrokeTransparency[element] then
[Link] =
initialUIStrokeTransparency[element]
end
end
for _, child in ipairs(DialogueReplies:GetChildren()) do
if child:IsA("Frame") then
child:Destroy()
end
end
if [Link] ~= nil and
[Link] then
local humanoid =
[Link]:FindFirstChildOfClass("Humanoid")
if humanoid and originalWalkSpeed then
[Link] = originalWalkSpeed
end
end
if [Link] then
StarterGui:SetCoreGuiEnabled([Link], true)
end
if [Link] then
StarterGui:SetCoreGuiEnabled([Link], true)
end
if [Link] then
StarterGui:SetCoreGuiEnabled([Link], true)
end
if [Link] then
[Link] = [Link]
end
if humanoidDiedConnection then
humanoidDiedConnection:Disconnect()
humanoidDiedConnection = nil
end
if characterAddedConnection then
characterAddedConnection:Disconnect()
characterAddedConnection = nil
end
dialogueActive = false
end)
end
local function connectContinueButton()
if ContinueButtonConnection then
ContinueButtonConnection:Disconnect()
end
ContinueButtonConnection =
ContinueButton.MouseButton1Click:Connect(function()
if isTyping then
isTyping = false
else
stopAutoScroll = true
[Link]()
end
end)
end
function startAutoScroll()
if autoScrollCoroutine then
[Link](autoScrollCoroutine)
end
stopAutoScroll = false
autoScrollCoroutine = [Link](function()
while dialogueActive and not stopAutoScroll do
wait([Link])
if dialogueActive and not isTyping and not stopAutoScroll then
[Link]()
end
end
end)
[Link](autoScrollCoroutine)
end
local function onCharacterAdded(character)
if dialogueActive then
if currentDialogue and [Link] ~=
nil then
local humanoid = character:WaitForChild("Humanoid")
if humanoid then
[Link] =
[Link]
if [Link] then
if humanoidDiedConnection then
humanoidDiedConnection:Disconnect()
end
humanoidDiedConnection =
[Link]:Connect(function()
[Link]()
[Link] = originalWalkSpeed -- Reset
WalkSpeed immediately if dialogue ends
end)
end
end
end
else
-- Do nothing; we don't want to reset originalWalkSpeed here
end
end
-- Ensure WalkSpeed is reset correctly when dialogue ends or on respawn
[Link]:Connect(onCharacterAdded)
function [Link](dialogueInfo)
if dialogueActive then return end
-- Check if the player is allowed to interact with the dialogue while dead
if not [Link] then
local humanoid = [Link] and
[Link]:FindFirstChildOfClass("Humanoid")
if humanoid and [Link] <= 0 then
return -- Do not start dialogue if the player is dead
end
end
dialogueActive = true
currentDialogue = [Link]
currentLayer = currentDialogue[[Link]]
[Link] = [Link]
dialogueIndex = 1
if [Link] and
[Link]:FindFirstChild([Link]) then
DialogueFrame =
[Link][[Link]]
DialogueText = [Link]
ContinueButton = [Link]
DialogueTitle = [Link]
DialogueReplies = [Link]
DialogueIcon = DialogueFrame:FindFirstChild("DialogueIcon")
CinematicBar1 = [Link]:FindFirstChild("CinematicBar1")
CinematicBar2 = [Link]:FindFirstChild("CinematicBar2")
else
DialogueFrame = DefaultDialogueFrame
DialogueText = DefaultDialogueText
ContinueButton = DefaultContinueButton
DialogueTitle = DefaultDialogueTitle
DialogueReplies = DefaultDialogueReplies
DialogueIcon = DefaultDialogueIcon
end
if [Link] and
script:FindFirstChild([Link]) then
ReplyFrame = script[[Link]]
else
ReplyFrame = DefaultReplyFrame
end
if ContinueButtonConnection then
ContinueButtonConnection:Disconnect()
end
elements = {
[Link],
[Link],
[Link],
[Link],
}
storeInitialUIStrokeTransparency(elements)
for _, element in ipairs(elements) do
[Link] = 1
local uiStroke = element:FindFirstChildOfClass("UIStroke")
if uiStroke then
[Link] = 1
end
end
[Link] = 1
[Link] = [Link](0.5, 0, 0.6, 0)
[Link] = true
updateDialogueIcon()
updateDialogueTitle()
-- Store originalWalkSpeed once at the start of the dialogue
if [Link] ~= nil and [Link]
then
local humanoid = [Link]:FindFirstChildOfClass("Humanoid")
if humanoid then
originalWalkSpeed = [Link]
[Link] = [Link]
end
end
local tweenInFrame = TweenService:Create(DialogueFrame, MainTweenInfo,
{Position = [Link](0.5, 0, 0.5, 0)})
local tweens = {}
for _, element in ipairs(elements) do
[Link](tweens, TweenService:Create(element, MainTweenInfo,
{GroupTransparency = 0}))
local uiStroke = element:FindFirstChildOfClass("UIStroke")
if uiStroke then
local initialTransparency = initialUIStrokeTransparency[element]
or 0
[Link](tweens, TweenService:Create(uiStroke, MainTweenInfo,
{Transparency = initialTransparency}))
end
end
tweenInFrame:Play()
for _, tween in ipairs(tweens) do
tween:Play()
end
if [Link] then
local tweenInBar1 = TweenService:Create(CinematicBar1, MainTweenInfo,
{Position = [Link](0.5, 0, -0.14, 0)})
local tweenInBar2 = TweenService:Create(CinematicBar2, MainTweenInfo,
{Position = [Link](0.5, 0, 1.14, 0)})
tweenInBar1:Play()
tweenInBar2:Play()
end
if [Link] then
[Link] = [Link]
[Link] = 0
BackgroundSound:Play()
local tweenInBackgroundSound = TweenService:Create(BackgroundSound,
MainTweenInfo, {Volume = [Link]})
tweenInBackgroundSound:Play()
end
if [Link] ~= nil then
characterAddedConnection =
[Link]:Connect(onCharacterAdded)
end
if [Link] then
StarterGui:SetCoreGuiEnabled([Link], false)
end
if [Link] then
StarterGui:SetCoreGuiEnabled([Link], false)
end
if [Link] then
StarterGui:SetCoreGuiEnabled([Link], false)
end
if [Link] then
[Link] = [Link]
[Link] = [Link]
end
[Link]()
connectContinueButton()
if [Link] > 0 then
startAutoScroll()
end
end
return dialogues