Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I perform a function when a dialog choice is selected?

I want a player who selects a dialog choice to be kicked once they select that choice, but I have no clue where to start. I've been searching online for a while but none of the codes seem to work.

local Dialog = script.Parent

Dialog.DialogChoiceSelected:connect(function(Player, Choice)
        game.Players.LocalPlayer:Kick()
end)

4 comments

0

Show us your code. It gives us a better idea on how we can help you.

0

Is that in a localscript?

0

still doesn't not work

0

chat service

1 answer

✓ Accepted answer

Tested your script. I think it's not working because LocalScripts don't run under dialogs. They only run under (from the wiki):

  • Player Backpacks
  • Player Characters
  • StarterGui/PlayerGui
  • PlayerScripts
  • ReplicatedFirst

Or maybe DialogChoiceSelected doesn't work under local scripts but I think it's because of where you parent it.

This is actually easy to fix. Use a server (regular) script, and since DialogChoiceSelected returns the player, we can use that to find and kick the player.

Here's what your script should look like :

local Dialog = script.Parent

Dialog.DialogChoiceSelected:Connect(function(Player, Choice)
	Player:Kick()
end)

-- Note this kicks the player using the dialog when picking ANY choice

Hope this helps!

2 comments

0

this does not work for me...

0

^ Hi! This answer is a bit outdated now as DialogChoiceSelected now only works in local scripts/clientsided, so please use that instead. More info here: 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.