What do you want to achieve?
I am trying to make it so when a dialog choice is selected, bandits appear into the map.
What is the issue?
It wont work, I dont know why.
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)
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)
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
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.