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

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

Asked by 3 years 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
1
Answered by 3 years 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.
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

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

Answer this question