function Chosen(player, dialog) dialog.Name = "KillsYou" if dialog.Name == "KillsYou" then game.Players.LocalPlayer.Character.Humanoid.Health = 0 end end script.Parent.DialogChoiceSelected:connect(Chosen)
I currently am trying to setup a dialog option where when you select a specific option, it will kill you. However, the code does nothing. I have the script placed inside of the dialog option that is called "KillsYou". I have tried setting it as a local script and a regular script but to no avail.
The console outputs:
DialogChoiceSelected is not a valid member of Workspace "Workspace"
Any help would be much appreciated!!!
To fix error u need do this
local dialog = script.parent-- do parent until the dialog name comes up
I was able to solve the issue with the code and get it to work.
Firstly, I had the script in the wrong location. I made it a local script and placed it inside of StarterPlayerScripts instead of inside the Dialog. I then modified the code as such:
local dialog = workspace.Model.Head.Dialog local function onSelected(player, choice) if choice == dialog.(PATH_TO_CHOICE).KillsYou then wait(1) local humanoid = player.Character.Humanoid humanoid.Health = 0 end end dialog.DialogChoiceSelected:Connect(onSelected)
After making these changes, the script now worked properly!
Apparently your script is in the workspace and you are looking for something called DialogChoiceSelected inside Workspace, even though there is nothing called DialogChoiceSelected in the workspace. Hence the error that "DialogChoiceSelected" is not a member of Workspace.
You are just missing the correct path. It should be script.parent.[your dialog].DialogChoiceSelected:Connect() instead of script.parent.DialogChoiceSelected:Connect()