I am wondering how i can detect if a player talked with a npc using the dialogue, for context i am creating a shop that uses dialogue to buy the items.
How do i detect when a player talks to a npc with a dialogue?
1 answer
If you are using Dialogue, you can use the event DialogChoiceSelected. This event detects whenever one of the dialogue choices has been selected in a dialogue.
For example, I have placed a TestDummy and have placed a Dialogue Onto It's Head, Then Inside the Dialogue, I have placed 3 Dialogue Choices.
I then created a local script and placed it onto StarterCharacter(this event only works locally).
local Dialogue = workspace.Dummy.Head.Dialog
Dialogue.DialogChoiceSelected:Connect(function(player, dialogueInstance)
print(player, dialogueInstance) --It has default params that gives you whoever triggered it and the dialogue choice,
--Do whatever you want here.
end)
Whenever one of the dialogue choices have been selected by the player, this event will trigger.
Note: Dialogue and DialogueChoices are two different things, DialogueChoices should be placed inside Dialogue.
If you want to read more about it, here is the link to the documentation. https://developer.roblox.com/en-us/api-reference/event/Dialog/DialogChoiceSelected
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
Good answer.
Thank you I didn't even know about "DialogueChoiceSelected" event Im sorta new to scripting.
So like https://pastebin.com/CNCPvaAz
Kind of, you used the event correctly, but I would recommend using a remote event because you are using a local script. Using a local script to give tools to players is not safe and it may break the tool. So I would recommend you fire a remote event to validate how much Currency the player has on the server to prevent exploiters. https://pastebin.com/SNzpLHZY
Here is what the server script is suppose to look like.