Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

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

Asked by
Asalea 25
1 year ago
Edited 1 year 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!!!

3 answers

Log in to vote
0
Answered by 1 year ago

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 — 1y
0
Your very welcome blue_bunny0fficl 98 — 1y
Ad
Log in to vote
1
Answered by
Asalea 25
1 year 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!

Log in to vote
0
Answered by
xXMadonXx 190
1 year ago
Edited 1 year ago

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()

Answer this question