NPC dialog shop won't work

I’m trying to make a gamepass store with an NPC dialog to activate the GUI, I’m new to dialog NPCs so I’ve probably just made a simple mistake. The script doesn’t appear to run (local script) because I don’t get any of the warn("1") things come up. The image below is the NPC and dialog.

-- Shop runner script 


local main = script.Parent
local yes = script.Parent.aYes

main.DialogChoiceSelected:connect(function(player,dialog)
	local gui = script.Parent.Shop -- Change Shop To The Name Of The Gui.
	warn("1")
	if dialog.Name == yes then
		warn("2")
		game:GetService("Lighting").Blur.Enabled = true
		gui:Clone().Parent = player.PlayerGui
	else
		warn("3")
	end
end)

image

if the local script is not in a character it doesn’t run

parent it to game.starterplayer.starterplayerscripts
please set me as solved is my solution works
it can be undone

1 Like

You can’t run client scripts in workspace. Either switch to a serverscript or place the script into StarterGui / StarterPlayerScripts and set the parent to the NPC in workspace

This worked but how do you get it to do something on a certain option choice? Do you just put if dialog.Name == yes then if you use the script I made earlier?

yes, you need to check if the name == the option and then do it

local main = script.Parent
main.DialogChoiceSelected:connect(function(player,dialog)
	local gui = script.Parent.Shop -- Change Shop To The Name Of The Gui.
	print('an option is selected')
	if dialog.Name == 'yes' then
	        print('the option is called "yes" ')
		--do things if the option is called "yes" 
	else
		print('the option is not called "yes"')
                --do things if the option is not called "yes" 
	end
end)

Right, I’ve got the blur to come on but now can’t get the shop GUI to appear. Code is below.

local main = game.Workspace.popo.Head.Dialog
local yes = main.aYes
local blur = game.Lighting.Blur

main.DialogChoiceSelected:connect(function(player,dialog)
	local gui = game.StarterGui.Shop["Part 1"] -- Change Shop To The Name Of The Gui.
	if dialog.Name == 'aYes' then
		gui.Visible = true
		blur.Enabled = true
	else
		return
	end
end)

starterGui is for coreGui
you need to use

game.Players.LocalPlayer.PlayerGui

or parent the local script to starterGui

1 Like

Thanks for the help! It has worked now.