Problem with Dialogs

So I am trying to make a player teleport when they pick a certain choice in a dialog choice. Here is my code:

local Dialog = script.Parent.Parent
local DC1 = Dialog.Dialogpart.DialogChoice1
local DC2 = Dialog.Dialogpart.DialogChoice2

Dialog.DialogChoiceSelected:connect(function(player,choice)
	if choice == DC1 then
		local humanoid = player.Character:FindFirstChild("Humanoid")
		if humanoid ~= nil then
			humanoid.Torso.CFrame = CFrame.new(-705.6, 8.319, 141.9)
		end
	end
end)

It comes up with this error:
12:56:42.868 Dialogpart is not a valid member of Dialog "Workspace.Centurion.Head.Dialog" - Server - Script:2

The script is a server script inside of the dialog choice.

1 Like

What does the hierarchy look like? Looks like your referencing the Dialog instance here:

local Dialog = script.Parent.Parent

But then when referencing DC1 and DC2, you’re doing “Dialog.Dialogpart”. Are you sure you didn’t mean to do:

local DC1 = Dialog.DialogChoice1
local DC2 = Dialog.DialogChoice2

didn’t work. It gives me this error now:
13:16:09.693 DialogChoice1 is not a valid member of Dialog "Workspace.Centurion.Head.Dialog" - Server - Script:2

Can you send a screenshot of the hierarchy?

Yes. Here is the hierarchy:

Were did the dialogpart come from? Its dialogchoice rite?

1 Like

It should be like this:

local dialog = script.Parent.Parent
local dc = dialog.DialogChoice

I don’t understand where you’re getting Dialogpart from.

1 Like

There is no more error but it is not teleporting still. The code that I am using to teleport the player works and I have used it in other games before.

1 Like

I did provide the code. In the topic.

And I have no Idea what you mean by this.

Sorry, I didn’t read the question properly… If it doesn’t come up with any errors, you can try using print statements to detect how far the code runs and figure out the issue based on where it stops, like this:

Dialog.DialogChoiceSelected:Connect(function(player, choice)
    print(choice + " was selected")

    if choice == DC1 then
        print("DC1 was selected")

        local humanoid = player.Character:FindFirstChild("Humanoid")
        if humanoid ~= nil then
            print("Humanoid detected")
            humanoid.Torso.CFrame = CFrame.new(-705.6, 8.319, 141.9)
            print("Teleport not working?")
        end
    end
end)
1 Like