Help with creating GUI with dialog and choices

Hello, I am trying to create a Gui that has dialog with sometimes having choices for the player to pick. I’m still fairly new to lua scripting, so my scripting is pretty messy.

local frame = script.Parent.Frame
local choice1 = script.Parent.Frame.Choice1
local choice2 = script.Parent.Frame.Choice2
local choice3 = script.Parent.Frame.Choice3
local textbutton = script.Parent.Frame.TextButton --This button is used when there is no choices to click anywhere and advance the conversation.
local choicearrow1 = script.Parent.Frame["Choice Arrow1"]
local choicearrow2 = script.Parent.Frame["Choice Arrow2"]
local choicearrow3 = script.Parent.Frame["Choice Arrow3"]
local npc = script.Parent.Frame.NPCName
local npcText = script.Parent.Frame.Text
local obj = game.Workspace.Objectives

--objective values

local yesRideobj = game.Workspace:WaitForChild("Objectives"):WaitForChild("YesRide")
local yesRide2obj = game.Workspace:WaitForChild("Objectives"):WaitForChild("YesRide2")
local yesRide3obj = game.Workspace:WaitForChild("Objectives"):WaitForChild("YesRide3")
local noRideobj = game.Workspace:WaitForChild("Objectives"):WaitForChild("NoRide")
local noRide2obj = game.Workspace:WaitForChild("Objectives"):WaitForChild("NoRide2")
local noRide3obj = game.Workspace:WaitForChild("Objectives"):WaitForChild("NoRide3")


wait(12)

frame.Visible = true

npcText.Text = "What time are you getting out? 6?"

choice1.MouseEnter:Connect(function()
	choicearrow1.Visible = true
end)

choice1.MouseLeave:Connect(function()
	choicearrow1.Visible = false
end)

choice2.MouseEnter:Connect(function()
	choicearrow2.Visible = true
end)

choice2.MouseLeave:Connect(function()
	choicearrow2.Visible = false
end)
choice3.MouseEnter:Connect(function()
	choicearrow3.Visible = true
end)

choice3.MouseLeave:Connect(function()
	choicearrow3.Visible = false
end)

local function dialogCloser()
	frame.Visible = false
end

local function boxclicked()
	if obj.Conversation1.Value == true then
		npcText.Text = "Want me to pick you up?"
		textbutton.Visible = false
		choice1.Visible = true
		choice2.Visible = true
		choice1.Text = "Yeah, it's too far to walk."
		choice2.Text = "No, I'll get a ride."
	end
end

local function yesRide()
	npcText.Text = "I might arrive late, gonna be very busy in the morning..."
	choice1.Visible = false
	choice2.Visible = false
	textbutton.Visible = true
	obj.Conversation2.Value = true
	obj.Conversation1.Value = false
	obj.YesRide.Value = true
end

local function noRide()
	npcText.Text = "Perfect. I was just asking to be nice."
	choice1.Visible = false
	choice2.Visible = false
	obj.Conversation2.Value = true
	obj.Conversation1.Value = false
	obj.NoRide.Value = true
end

local function noRide2()
	npcText.Text = "I'll make sure to have a meal ready for you when you get home."
	obj.NoRide2.Value = true
end

local function noRide3()
	npcText.Text = "Enjoy your first day on the job!"
	obj.NoRide3.Value = true
end

local function yesRide2()
	npcText.Text = "I'll have a meal ready for you when we get home."
	obj.YesRide2.Value = true
end

local function yesRide3()
	npcText.Text = "Have fun on your first job in life!"
	obj.YesRide3.Value = true
end

if obj.Conversation1.Value == true then
	textbutton.Activated:Connect(boxclicked)
end

if obj.Conversation1.Value == true then
	choice1.Activated:Connect(yesRide)
end

yesRideobj:GetPropertyChangedSignal("Value"):Connect(function()
	if yesRideobj.Value == true then
		textbutton.Activated:Connect(yesRide2)
	end
end)

yesRide2obj:GetPropertyChangedSignal("Value"):Connect(function()
	if yesRide2obj.Value == true then
		textbutton.Activated:Connect(yesRide3)
	end
end)

yesRide3obj:GetPropertyChangedSignal("Value"):Connect(function()
	if yesRide3obj.Value == true then
		textbutton.Activated:Connect(dialogCloser)
	end
end)

noRideobj:GetPropertyChangedSignal("Value"):Connect(function()
	if noRideobj.Value == true then
		textbutton.Activated:Connect(noRide2)
	end
end)

noRide2obj:GetPropertyChangedSignal("Value"):Connect(function()
	if noRide2obj.Value == true then
		textbutton.Activated:Connect(noRide3)
	end
end)

noRide3obj:GetPropertyChangedSignal("Value"):Connect(function()
	if noRide3obj.Value == true then
		textbutton.Activated:Connect(dialogCloser)
	end
end)

Basically, if the player picks choice1 then it will do the function yesRide() and the conversation will advance to function yesRide2(). The problem is, the conversation just stops advancing any further from the function yesRide2() even though the button (textbutton) is being clicked and it’s supposed to advance the conversation. The only thing I can think of is making a bunch of Gui buttons in the starter gui each only appearing when they need to. But there has to be a better way to do this right? If anyone can give me any tips on improving this, I’d be very grateful.

2 Likes