2

# Trying to have a dialog option kill the player when selected?

Asalea 25
20 days ago
Edited 20 days ago
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!!!

0

To fix error u need do this

local dialog = script.parent-- do parent until the dialog name comes up

0
The code didn't work until I moved it into StarterPlayerScripts, but this definitely helped a lot. Thank you!!! Asalea 25 — 19d
0
Your very welcome blue_bunny0fficl 98 — 19d
1
Asalea 25
19 days ago

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!