Script on Dialog choice

  1. What do you want to achieve?
    I am trying to make it so when a dialog choice is selected, bandits appear into the map.
  2. What is the issue?
    It wont work, I dont know why.
  3. What solutions have you tried so far?
    I tried to look for a solution but couldnt find a problem.
local dialog = workspace.NoobQuest.Head.Dialog

local function onSelected(player, choice)
	if choice == dialog.BanditChoice.Confirm then
		game.ServerStorage.Bandits.Parent = game.Workspace
	end
end

dialog.BanditChoice.Selected:Connect(onSelected)
6 Likes

Try using choice.Name and Confirm.Name to check it

3 Likes

Like this?

local dialog = workspace.NoobQuest.Head.Dialog



local function onSelected(player, choice)
	if choice == dialog.BanditChoice.Confirm and dialog.BanditChoice.Confirm.Name == ("Confirm") then
		game.ServerStorage.Bandits.Parent = game.Workspace
	else
		print ("failed")
	end
end

dialog.BanditChoice.Selected:Connect(onSelected)
2 Likes

If choice.Name == dialog.confirm.name

1 Like

They dont have the same name though
image

1 Like

btw unreleated but you should clone the bandaits instead of putting them there.

1 Like

Thanks, I will try it out right now.

1 Like

you should really make your own gui dialog, this creates more possibilities and customizable, the roblox dialog is just mostly made for talking not using it to do things

1 Like

Its probably the better choice, thanks!

1 Like

Now i understand, my method is useless in this case

1 Like

heres a jumpstart for ya

local button = script.parent
button.mousebutton1click:connect(function(plr)
local clone = game.ServerStorage.Bandits:clone
clone.Parent = workspace
end)

put it in a gui button, i made some code grammer errors

1 Like

I would just say to name every answer as what the script will do like

For example i would name everything as “NPC_Bandits_Confirm” “NPC_TakeApple_Confirm” so that if more Confirm dialogue will happen there will be no multiple functions

local dialog = workspace.NoobQuest.Head.Dialog

local function onSelected(player, choice)
	if choice.Name=="Confirm" then
--Spawn
	end
end

dialog.BanditChoice.Selected:Connect(onSelected)

Assuming this is a serverscript, you should keep in mind that Dialog instances only fire connections to the client, so the script should rather be a local script that clones something from ReplicatedStorage.

To solve this, we can convert the script into a localscript. (keep in mind to parent it to an environment where localscripts are ran, such as starterpack, starterplayerscripts, startercharacterscripts, etc)

There’s also the issue that .Selected:Connect() isn’t a proper event of Dialog options, and that dialogue choices instead use DialogChoiceSelected.

To solve this, we’ll call DialogChoiceSelected on the head Dialog instance, and check if the choice selected is the same as the Confirm instance. If so, then we’ll proceed to clone the bandits from ReplicatedStorage.

local dialog = game.Workspace:WaitForChild("NoobQuest"):WaitForChild("Head"):WaitForChild("Dialog") --wait for dialog to exist

dialog.DialogChoiceSelected:Connect(function(player, choice) --function for when a dialogue choice is picked
	if choice.Name == dialog.BanditChoice.Confirm.Name then --check to see if the choice selected is the confirm option for the bandit quest
		game.ReplicatedStorage.Bandits:Clone().Parent = game.Workspace --clone the instance to workspace, this is so that it can be used more than once (not cloning it will make it be parented in its entirety, leaving nothing behind)
	end
end)

Note that since you’re cloning from the client, the bandits will only be visible on that player’s screen. If you want to spawn it on the server, try looking into RemoteEvents, which allow for client-server communication.

9 Likes