This post was heavily updated to ensure a well-guided and updated approach on using the DialogChoiceSelected
event.
Well…
The core issue in your script is the inadequate DialogChoiceSelected
event utilization. This method is only present within the Dialog
instance, meaning that it’s non-existent to the DialogChoice
. Below is a step-by-step guidance on how to properly use the event, following the Roblox’s official documentation.
Application guide.
This guide overviews a standard approach on building and programming the event properly. You can also opt for a more complex approach by using a ModuleScript
and setting up the events and quests in it, calling it when necessary.
- First thing you should do is add separate lines for calling Roblox-related events.
local Workspace = game:GetService("Workspace")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
- Next up, rewrite the way you call your variables.
local zombieQuest = Workspace:WaitForChild("QuestZombie")
local questDialogBox = zombieQuest:FindFirstChild("Dialog")
local triggerQuestChoice = questDialogBox:FindFirstChild("DialogChoice")
local questConfigs = ReplicatedStorage:WaitForChild("QuestConfigs")
local brainHuntQuest = questConfigs:WaitForChild("BrainHunt")
local questToggle = brainHuntQuest:WaitForChild("ToggleQuest")
local questToggled = brainHuntQuest:WaitForChild("InProgress")
- Next off, I’ll be remaking the function you’re using to call the zombie quest and fire the server in order to activate it.
questDialogBox.DialogChoiceSelected:Connect(function(player, dialogChoice)
local targetUserDialog = "How many should I collect?" -- The required user dialog.
if player then -- Checks if the player is an existent instance.
if dialogChoice.UserDialog == triggerQuestChoice.UserDialog and triggerQuestChoice.UserDialog == targetUserDialog and not questToggle.Value then
-- Creates a comparison based on the selected user dialog and the target user dialog, if the selected user dialog matches the targetUserDialog, and if the questToggle.Value is set to false.
questToggle:FireServer() -- Fires the server.
else
print("Prompted DialogChoice does not fits the one or more requirements based on the event connection conditional.") -- Debugging.
end
else
print("Player is a non-existent instance.") -- Debugging,
end
end)
Code explanation and review.
The code above starts off by rewriting the way you call Roblox-related services, designs the necessary variables, and then begins with the code itself. It starts off by setting the required user dialog to start off with the quest, runs a conditional check to see if the player is an existent instance, and then another conditional check. It makes sure that both user dialogs pair with one another, if the triggerQuestChoice.UserDialog
matches with the targetUserDialog
, and if the value of the questToggle
is false. If all these requirements are met, the questToggle
event will fire the server.
Full code.
local Workspace = game:GetService("Workspace")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local zombieQuest = Workspace:WaitForChild("QuestZombie")
local questDialogBox = zombieQuest:FindFirstChild("Dialog")
local triggerQuestChoice = questDialogBox:FindFirstChild("DialogChoice")
local questConfigs = ReplicatedStorage:WaitForChild("QuestConfigs")
local brainHuntQuest = questConfigs:WaitForChild("BrainHunt")
local questToggle = brainHuntQuest:WaitForChild("ToggleQuest")
local questToggled = brainHuntQuest:WaitForChild("InProgress")
questDialogBox.DialogChoiceSelected:Connect(function(player, dialogChoice)
local targetUserDialog = "How many should I collect?" -- The required user dialog.
if player then -- Checks if the player is an existent instance.
if dialogChoice.UserDialog == triggerQuestChoice.UserDialog and triggerQuestChoice.UserDialog == targetUserDialog and not questToggle.Value then
-- Creates a comparison based on the selected user dialog and the target user dialog, if the selected user dialog matches the targetUserDialog, and if the questToggle.Value is set to false.
questToggle:FireServer() -- Fires the server.
else
print("Prompted DialogChoice does not fits the one or more requirements based on the event connection conditional.") -- Debugging.
end
else
print("Player is a non-existent instance.") -- Debugging,
end
end)
Glad to assist, and hope it helped! 