I'm trying to make a dialog choice that when selected plays a sound effect. Can somebody help me out?
✓ ANSWER ACCEPTED
How would I make a dialogue option that plays a sound when selected?
1 answer
✓ Accepted answer
very easy and simple :) by using DialogChoiceSelected we can check to see if a certain choice was selected, and do something.
- firstly, you need dialog. and a character. this is a very good API that has a lot of customization:
https://www.roblox.com/library/59391730/Advanced-Player-AI
in the player model go to "Head", insert Dialog. under Dialog insert DialogChoice. I inserted two, "Yes" and "No" make sure the names are spelled exactly as you put them in code (case sensitive)
insert an Audio in ReplicatedStorage and make a local variable pointed to that audio
the following script goes under StarterGui
local Dialog = game.Workspace.Player.Head.Dialog
local Voice = game.ReplicatedStorage["YES! YES!"]
Dialog.DialogChoiceSelected:Connect(function(player,choice)
if choice.Name == "No" then
player.Character.Humanoid.Health = 0
elseif choice.Name == "Yes" then
Voice:Play()
end
end)
and boom. if you say no you die, if you say yes the audio played
hope I helped, accept the answer if I did :)
This discussion is preserved as it was. New answers, comments, and votes are closed.
