Script isn't working when choosing a dialog

so i’m trying to make it whenever you pick a chat from the dialog it runs a code but it doesn’t work for some reason… and i have no idea why
theres no errors but it prints " he didnt choose it :sob: " instead, even when i pick the dialog that’s supposed to run the script
its a local script btw, and its inside the startergui
image

hope someone helps me to fix it
here’s the script :

local di = game.Workspace.Rig.Head.Dialog
local anim = di.Parent.Parent.Humanoid.Animator.Animation

di.DialogChoiceSelected:Connect(function(plr,choice)
	if choice == game.Workspace:WaitForChild("Rig").Head.Dialog.DialogChoice.DialogChoice.UserDialog then
		game.ServerStorage.Portal:Clone().Parent = game.Workspace
		local play = anim.Parent:LoadAnimation(anim)
		play:Play()
	
	else
		print("he didnt choose it :sob:")
	end
end) ```

try to get the dialog earlier and not in the if condition.
like that:

di.DialogChoiceSelected:Connect(function(plr,choice)
    local dialog = game.Workspace:WaitForChild("Rig").Head.Dialog.DialogChoice.DialogChoice.UserDialog
	if choice == dialog then
		game.ServerStorage.Portal:Clone().Parent = game.Workspace
		local play = anim.Parent:LoadAnimation(anim)
		play:Play()
	
	else
		print("he didnt choose it :sob:")
	end
end)

If this doesn’t work, check if the path is correct.

it just printed and didnt work… sadly, and i did check its path


its the same one in the script but for some reason doesn’t work

Not surprisingly, I just noticed the script, you have errors. First, you pass the plr argument, although you only need to pass one choice argument, we remove plr.

Secondly, there was an error when receiving the animator.

Thirdly, remove :WaitForChild() since the path is already known.

local di = game.Workspace.Rig.Head.Dialog
local anim = game.ReplicatedStorage:WaitForChild("YourAnimation") -- The animation should be in storage

di.DialogChoiceSelected:Connect(function(choice)
	if choice.Name == "UserDialog" then
		local portal = game.ServerStorage.Portal:Clone()
		portal.Parent = game.Workspace

		local humanoid = di.Parent.Parent:FindFirstChild("Humanoid")
		if humanoid then
			local animator = humanoid:FindFirstChild("Animator")
			if not animator then
				animator = Instance.new("Animator", humanoid)
			end
			
			local play = animator:LoadAnimation(anim)
			play:Play()
		end
	else
		print("he didnt choose it :sob:")
	end
end)

P.S* I forgot to note that it is not the object itself that needs to be compared (in your case it is UserDialog), but their names need to be compared.

1 Like

it actually worked !!! thanks i appreciate your help a lot ,
also i found out that i had to put plr to it, becuase when i tried to print choice it printed the player name instead… and i came up with this

local di = game.Workspace.Rig:WaitForChild("Head").Dialog
local anim = game.ReplicatedStorage:WaitForChild("Animation")

di.DialogChoiceSelected:Connect(function(plr,choice)
	if choice.Name == "sure" then
		local portal = game.ReplicatedStorage:WaitForChild("Portal"):Clone()
		portal.Parent = game.Workspace

		local humanoid = di.Parent.Parent:FindFirstChild("Humanoid")
		if humanoid then
			local animator = humanoid:FindFirstChild("Animator")
			if not animator then
				animator = Instance.new("Animator", humanoid)
			end

			local play = animator:LoadAnimation(anim)
			play:Play()
		print(choice)
	end
	end end)

thanks again and your tips are really useful for my future scripting

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.