Hello! I have this Dialogue module that I use for my quests in my game. This system was working fine, but i decided to re-do the quest system, as all the quests were all in one script, which I thought was messy. It was working fine, but now, When i use the module.CloseDialogue()
function, It just doesn’t close. It doesn’t give me an error because I added an if statement that prevents it from giving an error; if PlayerGui then end
. Without this statement, I was given an “Attempted to index WaitForChild:() With Nil” Or something in that sort.
I will leave the code for the module here. Any help is appreciated!
local TS = game:GetService('TweenService')
local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out)
local active = false
local dialogue = {}
function dialogue.openDialogue(playerGui)
if playerGui then
local dialogueGui = playerGui:WaitForChild("DialogueGui")
local dialoguebox = dialogueGui:WaitForChild("DialogueBox")
dialoguebox.Size = UDim2.new(0,0,0,0)
dialoguebox.Visible = true
TS:Create(dialoguebox, tweenInfo, {Size = UDim2.new(0.536, 0,0.228, 0)}):Play()
task.wait(1)
end
end
function dialogue.closeDialogue(playerGui)
if playerGui then
local dialogueGui = playerGui:WaitForChild("DialogueGui")
local dialoguebox = dialogueGui:WaitForChild("DialogueBox")
TS:Create(dialoguebox, tweenInfo, {Size = UDim2.new(0,0,0,0)}):Play()
task.wait(1)
dialoguebox.Visible = false
end
end
function dialogue.writeText(text,interval,playerGui)
if playerGui then
local dialogueGui = playerGui:WaitForChild("DialogueGui")
local dialoguebox = dialogueGui:WaitForChild("DialogueBox")
local dialogueText = dialoguebox:WaitForChild("TextLabel")
dialogueText.Text = ""
for _, letter in pairs(string.split(text,"")) do
dialogueText.Text ..= letter
task.wait(interval)
end
end
end
function dialogue.IsActive()
return active
end
return dialogue