Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to trigger a function when dialog choice is selected?

Asked by 4 years ago

I was making a NPC that had some dialog and he would offer you an item. If the player clicked yes, the script was supposed to find an item from ServerStorage and put it in their Backpack. The only problem is that every tutorial I try says to use "DialogChoiceSelected" but Output says "DialogChoiceSelected is not a valid member if DialogChoice". Was testing to see if it worked by deleting the option when it was selected so the player could only say no, but I got the error in Output and the option didn't disappear. Here's the script:

local d = script.Parent
d.DialogChoiceSelected:Connect(function()
    d:Destroy()
end)

I know this is not a request site but I have no idea how to do this.

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

The error says DialogChoiceSelected is not a valid member if DialogChoice because DialogChoice objects do not have a DialogChoiceSelected event. However, Dialog objects do. So put your script inside the Dialog object, not DialogChoice.

The DialogChoiceSelected event also passes the player who selected a choice, and the choice they selected. Here is the wiki link on the event: https://developer.roblox.com/en-us/api-reference/event/Dialog/DialogChoiceSelected

There is also a tutorial on the wiki on how to use Dialogs. Scroll all the way down to the "Scripting" section to see an example of how to use DialogChoiceSelected. I also recommend reading the whole article to understand how Dialog and DialogChoices work: https://developer.roblox.com/en-us/articles/Usage-of-dialogs

Ad

Answer this question