Triggering Something Locally with Dialog

  1. What do you want to achieve? I’m trying to make it so that there is an NPC with 3 final dialog options, and each one of them will do a different thing. The main thing I want is for a model inside the NPC’s model to disappear locally and also locally trigger a value if possible, so that you can place the item later.

  2. What is the issue? Nothing happens when I select the right final dialog option.

  3. What solutions have you tried so far? I have tried to get help from other sources, looked on the devforum for anything about this, and tried to do it myself, but I am unsuccessful.

This is my current code.

local mesh = game.Workspace:WaitForChild("Statue"):WaitForChild("Body"):WaitForChild("Head")
local model = mesh.Parent
local dialog = model.PlayerGui:WaitForChild("Dialog")
local value = game.StarterPlayer.StarterCharacterScripts:WaitForChild("GotBurger")

-- code to display the dialog

while true do
	local options = dialog:GetOptions()
	for i, option in ipairs(options) do
		if option:GetText() == "" then
			-- code to execute when the player finishes the entire set of dialog
			if option:GetText() == "get out of my temple >:(" then
				-- code to execute if the player selects the first final option
			elseif option:GetText() == "ok here you go" then
				script.Parent.Parent.Parent.BurgerItem:Destroy()
				value.Value = true
			elseif option:GetText() == "NO." then
				-- code to execute if the player selects the third final option
			end
			break
		end
	end
	wait()
end

Any help would be appreciated. Thank you.

is this on a server or local script?

This code is put in a local script.

First of all, is Model in line 2 an NPC? If so, line 3 doesn’t make sense as NPC’s can’t have a “PlayerGui”

And could you send a picture of the output if there is anything?

I’m not sure about the PlayerGui part. I got that from someone else, and it’s probably wrong. The output window says nothing, which is one of the reasons I’m so confused about this.

Yes, the PlayerGui part is wrong.

the Dialog is located in the NPC’s head (Mesh), thus line 3 will not work.
GetOptions() does not even exist, so line 9 is broken.
There’s a bunch more stuff wrong, but I rewrote it for you:

local mesh = game.Workspace:WaitForChild("Statue"):WaitForChild("Body"):WaitForChild("Head")
local model = mesh.Parent
local dialog = mesh:WaitForChild("Dialog")
local value = game.StarterPlayer.StarterCharacterScripts:WaitForChild("GotBurger")

-- code to display the dialog

dialog.DialogChoiceSelected:Connect(function(plr, Choice)
if Choice == "" then

if Choice == "get out of my temple >:(" then
-- code to execute if the player selects the first final option
elseif Choice == "ok here you go" then
script.Parent.Parent.Parent.BurgerItem:Destroy()
value.Value = true
elseif Choice == "NO." then
-- code to execute if the player selects the third final option
end

end
end)

Try it out, if it doesn’t work then I’ll be happy to keep helping you :slight_smile:

It still doesn’t trigger anything when the correct option is given.

Anything in the output? (ignore this sentence i need to meet the character minimum)

Still nothing showing in the output window. I ran it twice, but there’s nothing.

Wait, where is this script located? It could be not working and outputting because its not in a valid localscript holder

The local script is in the head of the NPC.

Ah, that explains why it does not work. Place the script in StarterPlayerScripts or ScreenGui, and if it doesn’t work, change it into a Server Script and put it back in the head

If I put it in a server script, won’t that make everything that is meant to be triggered happen for everyone in the server?

You’re right. You can set the Dialog type to MultiplePlayers and it would act the same way.

That’s nice, but if the events for the dialog choice trigger in a server script, which will activate it for everyone, that defeats the purpose of the script, because the events are only meant to trigger for the people who have gotten the right dialog.

True. Just try it for now with the localscript and see if it works fine

It sadly did not work. I’m not sure what to try next, since a server script won’t work either.

Check the output again this time, as now we are in a proper localscript container and it will output

There’s still nothing in the output.