so im making a script that gives an apple to an npc by dialouge if they have one but nothing is working or printing:
local dialog = script.Parent.Parent
print("Script is running")
dialog.DialogChoiceSelected:Connect(function(player, choice)
print("DialogChoiceSelected event triggered")
if choice == script.Parent then
print("Choice is 'give'")
local backpack = player:FindFirstChild("Backpack")
if backpack then
print("Backpack found")
local apple = backpack:FindFirstChild("Apple")
if apple then
apple:Destroy()
print("Apple has been destroyed from the player's backpack.")
else
print("Apple not found in backpack")
end
else
print("Backpack not found")
end
else
print("Choice is not 'give'")
end
end)
The .DialogChoiceSelected event has to be called in a localscript or a modulescript required by a localscript, and that the localscript is in StarterPlayerScripts or something that the client controls. Make sure you’re calling it in the right place!
can u tell me what to edit in it bcuz this is all i think it needs and it doesnt work
local dialog = game.Workspace.Dummy.Head.apple
print("Script is running")
dialog.DialogChoiceSelected:Connect(function(player, choice)
print("DialogChoiceSelected event triggered")
if choice == script.Parent then
print("Choice is 'give'")
local backpack = player:FindFirstChild("Backpack")
if backpack then
print("Backpack found")
local apple = backpack:FindFirstChild("Apple")
if apple then
apple:Destroy()
print("Apple has been destroyed from the player's backpack.")
else
print("Apple not found in backpack")
end
else
print("Backpack not found")
end
else
print("Choice is not 'give'")
end
end)