Log in to vote

How do i detect when a player talks to a npc with a dialogue?

Asked by 4 days ago

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.

1 answer

Log in to vote
Answered by 4 days ago

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.

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.

Good answer. radiant_Light203 1050 — 4d
Thank you I didn't even know about "DialogueChoiceSelected" event Im sorta new to scripting. Black_Magic2533 22 — 3d
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. ArsonMcFlames 363 — 3d
Here is what the server script is suppose to look like. ArsonMcFlames 363 — 3d

Answer this question