DialogChoiceSelected not working

Don’t know what’s the error, but I am not to be able to find a solution for it

script.Parent.DialogChoiceSelected:Connect(function(plr, msg)
  print("fired")
  if msg == "I found Key" then
    local inv = plr.Backpack
    local chr = plr.Character
    if inv:FindFirstChild("Key_1") or chr:FindFirstChild("Key_1") then
		game.ReplicatedStorage["Key Events"].key1:FireClient(plr)	
    else
        script.Parent.DialogChoice.DialogChoice.ResponseDialog = "You don't have key :/"
     end
 end
end)

This is a script parented under the Dialog. Nothing is printing, no errors either.
image

I want to do something when player active the dialog

The DialogChoiceSelected only works for LocalScripts. Connect the LocalScript and Script with a RemoteEvent. See Remote Functions and Events.

1 Like

didn’t work

Could you please provide your code? Try debugging it.

Not sure what did not work for you, but here’s how it should be set up:

Script:

local rplfirst = game:GetService("ReplicatedFirst")
local event = rplfirst:FindFirstChild() -- What's the name of your event?

script.Parent.DialogChoiceSelected:Connect(function(plr, msg)
	print("fired")
	if msg == "I found Key" then
		event:FireServer()
	end
end)

LocalScript:

local rplfirst = game:GetService("ReplicatedFirst")
local event = rplfirst:FindFirstChild() -- Again, what is the name of your event?

event.OnServerEvent:Connect(function(plr) -- Player is the first parameter automatically.
	local inv = plr.Backpack
	local chr = plr.Character
	if inv:FindFirstChild("Key_1") or chr:FindFirstChild("Key_1") then
		game.ReplicatedStorage["Key Events"].key1:FireClient(plr)	
	else
		script.Parent.DialogChoice.DialogChoice.ResponseDialog = "You don't have key :/"
	end
end)

https://developer.roblox.com/en-us/api-reference/event/Dialog/DialogChoiceSelected

This event is client-side only and will not fire on the server. It should be connected to in either a LocalScript or a ModuleScript required by a LocalScript .

You should consult the official documentation before creating a thread.

thx for it but i already check the document and i made it to local script but still it didn’t worked

Already asked if you could provide your code? Try debugging it.

Did you remember to move the script’s location? Local scripts won’t execute if placed inside the ‘Workspace’ container.

Bare in mind you’ll need to fix your references once you’ve moved the script.

script.Parent.DialogChoiceSelected:Connect(function(plr, msg)
	print("fired")
end)

no result in console, means it didn’t fired(I used on local)

Could you provide the full script?

sorry I can’t but I tested this one separately and it still didn’t worked

script.Parent.DialogChoiceSelected:Connect(function(plr, msg)
	print("fired")
end)

sorry, my bad The local script only work with specific class and I inserted that script into the model