I'm making a quest system and I cannot seem to find what I did wrong

Here is the script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local QuestLibraries     = ReplicatedStorage:FindFirstChild("QuestLibraries")

     ----Libararies----
     local Dialogs = require(QuestLibraries:FindFirstChild("Dialogs"))
     local Quests  = require(QuestLibraries:FindFirstChild("Quests"))

     ----Varibles---
     local QuestGUI  = ReplicatedStorage:FindFirstChild("QuestDialog", true)
     local Quest        = script.configurations.Quest.Value
     local Enabled    = script.configurations.QuestEnabled.Value



    script.Parent.HumanoidRootPart.Touched:connect(function(hit)

if hit.Parent:FindFirstChild("Humanoid") ~= nil then
	
	local player    = game.Players:FindFirstChild(hit.Parent.Name)
	local playerGui = player:FindFirstChild("PlayerGui")
		
	if playerGui:FindFirstChild("QuestDialog") == nil then
		
		-----GUI parts-----			
		local GUI         = QuestGUI:Clone()
	    local Main        = GUI.Hold.Hold.Frame
	    local GUI_Name    = Main:FindFirstChild("TITLE", true)		
		local Decline_Btn = Main:FindFirstChild("Decline", true)
		local Accept_Btn  = Main:FindFirstChild("Accept", true)
		local NPC_Dialog  = Main:FindFirstChild("NPCDialog", true)
		
		------Data Tables---
		local Dialog_Data = Dialogs.dialog[Quest]
		
		------set defaluts--		 
		GUI_Name.Text = " ".. script.Parent.Name
	
	    GUI.Parent       = playerGui			
	 	Decline_Btn.Text = Dialog_Data["EXIT"]
	
		
		
		GUI.Parent = playerGui ------ puts gui into player gui
		--------- Get number of dialogs------
		
		local num_of_dialogs = 0
	
		for key, value in pairs(Dialog_Data) do
			if key ~= "EXIT" then
				num_of_dialogs = num_of_dialogs + 0.5
			
			end
		end
	end
	----- Go Through Dialog-----
	local dialog_num = 1
	
		
	NPC_Dialog.Text = Dialog_Data["NPC" .. dialog_num]
	Accept_Btn.Text = Dialog_Data["RES" .. dialog_num]
	
	Accept_Btn.MouseButton1Click:connect(function()
		    if dialog_num ~= num_of_dialogs then
				dialog_num = dialog_num + 1
				
				 NPC_Dialog.Text = Dialog_Data["NPC" .. dialog_num]
	             Accept_Btn.Text = Dialog_Data["RES" .. dialog_num]
			else
				GUI:Destroy()
			end
		end)

	end		
	
end)

Here is the error: Workspace.Lyden.QuestNPC:59: attempt to index global 'Dialog_Data' (a nil value)

Need Help Thank You!

2 comments

0

try adding 'local Dialog_Data' at the start of the script

0

I had to move a couple of things to the start but now its saying: Workspace.Lyden.QuestNPC:74: ')' expected (to close '(' at line 23) near ''