My GUI has an "Accept_btn" and a "Decline_btn". Decline closes the GUI and Accept moves onto the next dialog. I have a problem where the Accept button and the DialogBox both start with default text before finally moving onto the values I've set in my dictionary. I've tried moving things around to find the problem, but I can't seem to find it.

Script:

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

--libraries--

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

-- Variables --

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

script.Parent.Torso.Touched:Connect(function(part)
	
	end)
	
	if part.Parent:FindFirstChild("Humanoid") ~= nil then
		
		local Player = game.Players:FindFirstChild(part.Parent.Name)
		local PlayerGui = Player:FindFirstChild("PlayerGui")
		
		if PlayerGui:FindFirstChild("QuestDialog") == nil then
			
		----Create Quest Folder Function ----
		function StartQuest(QuestID, Quest_Data)
			local folder = Instance.new("Folder")
			folder.Name = QuestID
			
			local number = Instance.new("IntValue")
			number.Name = "Number"
			number.Parent = folder
			
			return folder
		end
			
		---- GUI Parts ----	
		local GUI = QuestGUI:Clone()
		local Main = GUI
		local GUI_Name = Main:FindFirstChild("Name", true)
		local Decline_Btn = Main:FindFirstChild("Decline", true)
		local Accept_Btn = Main:FindFirstChild("Accept", true)
		local NPC_Dialog = Main:FindFirstChild("DialogBox", true)
		
		---- Quest/Dialog Tables ----
		local Dialog_Data = Dialogs.dialog[Quest]
		local Quest_Data = Quests.quests[Quest]
		
		
		---- Set Defaults ----
		GUI_Name.Text = " " .. script.Parent.Name
		Decline_Btn.Text = Dialog_Data["NoQuest"]["EXIT"]
		
		GUI.Parent = PlayerGui -- Put GUI into Player GUI
		
		
		---- Get number of dialogs ----
		local num_of_dialogs = 0
		
		for key, value in pairs(Dialog_Data["NoQuest"]) do
			if key ~= "EXIT" then
				num_of_dialogs = num_of_dialogs + 0.5
			end
		end
		
		---- Go through dialog ----
		local OnQuest = false
		local IsComplete = false
		local dialog_num = 1
		
		if Player:FindFirstChild(Quest)~= nil then
			local Quest_Folder = Player:FindFirstChild(Quest)
			
			OnQuest = true
			
			if Quest_Folder.Number.Value >= Quest_Data["Nmbr"] then
				IsComplete = true
			end
			
		end

		Accept_Btn.MouseButton1Click:Connect(function()
			
		end)
			if OnQuest then
				Accept_Btn.Visible = false
				if IsComplete then
					NPC_Dialog = " " .. Dialog_Data["Quest"]["Complete"]
					Decline_Btn.Text = "Thanks!"
				else
					NPC_Dialog = " " .. Dialog_Data["Quest"]["Incomplete"]
					Decline_Btn.Text = "Oh, right."
				end
				
			else
				Accept_Btn.MouseButton1Click:Connect(function()	
					if dialog_num ~= num_of_dialogs then
					dialog_num = dialog_num + 1
					NPC_Dialog.Text = " " .. Dialog_Data["NoQuest"]["NPC" .. dialog_num]
					Accept_Btn.Text = Dialog_Data["NoQuest"]["RES" .. dialog_num]
				
					else
				local Quest_Folder = StartQuest(Quest)
				Quest_Folder.Parent = Player		
						
				GUI:Destroy()
			end
		end)
		
		end
		end
	end
	-- typewriter effect? 

ModuleScript:

local module = {}

module.dialog = {
	["QUEST01"] = {
		["NoQuest"]= {
			["NPC1"] = "Hey buddy... I need your help.";				
			["RES1"] = "What is it?";
			["NPC2"] = "I need you to go kill some rocks.";
			["RES2"] = "Sure.. I'll go kill.... wait... you said rocks?";
			["NPC3"] = "Yeah. I need you to kill rocks.";
			["RES3"] = "You can't kill a rock if it's not even living. But sure.";
			["EXIT"] = "I'm not helping you, loser.";
		},
		["Quest"] = {
			["Incomplete"] = "There's still too many rocks. Kill more please.";
			["Complete"] = "Thank you for killing those rocks for me! Here, take this.";
		}	
	}
}

return module

9 comments

0

You shouldn't nest events inside other events as if the outer event is fired multiple times, you're creating tons of connections for the nested events.

0

I thought that was the point, to allow the script to be used for other connections outside of the main script. Is that what prevents the text to be changed at the start of contact?

0

I'm not sure, you should give it a try. Make MouseButton1Click and Touched their own code block.

0

Do you mean to take them out of the if statements?

0

I mean don't have one event in the other. Touched should not be inside MouseButton1Click or vice versa.

0

I moved the MouseButton1Click above the if statement and I moved the Touched statement above the if statement, both in their own block. The Touched statement reads part as a nil value

0

Could you edit your question to show the current script?

0

I edited it. This is what it looked like.