1 | function Chosen(player, dialog) |
2 | dialog.Name = "KillsYou" |
3 | if dialog.Name = = "KillsYou" then |
4 | game.Players.LocalPlayer.Character.Humanoid.Health = 0 |
5 | end |
6 | end |
7 |
8 | 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
1 | 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:
01 | local dialog = workspace.Model.Head.Dialog |
02 |
03 | local function onSelected(player, choice) |
04 | if choice = = dialog.(PATH_TO_CHOICE).KillsYou then |
05 | wait( 1 ) |
06 | local humanoid = player.Character.Humanoid |
07 | humanoid.Health = 0 |
08 | end |
09 | end |
10 |
11 | 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()