How do i detect if a player clicked an Npc Dialog respond button

  1. So i have an Npc chat system whenever you click on it’s dialog button it starts chatting as normal but i want to make a script that detects when a player clicks a respond button, when the player clicks the respond button i need like a gui to pop up.

  2. So i have no idea about how could i detect if a player clicked the respond button.

  3. i have tried the “DialogChoiceSelected” function but i can’t find my way around it.

script that i have tried:

script.Parent.DialogChoiceSelected:Connect(function(plr)
game.ReplicatedStorage.DialogEvent:FireClient(plr)
end)
2 Likes

Alright, so I have figured out your problem.
In the object browser, it tells me you have to give two parameters, not one. DialogChoiceSelected is an event only in a Dialog, not a DialogChoice. Therefore, when you use it, in the function, you have to set the instance player, and the instance DialogChoice. It is also client-side and will not work in a serverscript. And since LocalScripts don’t work in workspace, you have to put it somewhere else. I tested it, and it worked well in ReplicatedFirst, but it most likely works in StarterPlayerScripts as well. For more info, go here:Dialog | Documentation - Roblox Creator Hub

For a good YouTube tutorial, I would recommend this:https://www.youtube.com/watch?v=KadArY-cJ9A

And since you want an event to fire on the client, I would suggest using a BindableEvent.
Here is the working code(in ReplicatedFirst or StarterPlayerScripts):

local Dialog = workspace.NPC.Head.Dialog


function selected(plr, choice)
	if choice == Dialog.DialogChoice then
		--code to fire a BindableEvent or whatever you want to happen.
	end
end

Dialog.DialogChoiceSelected:Connect(selected)

Please mark this as the solution if it helps so if anyone else has the same problem, they can quickly get their solution.

Hope this helps!

3 Likes

Thank you so much for the support.

1 Like