Script not running

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)
1 Like

Where’s the script is? You need to know that for example localscripts are not working inside workspace.

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!

its inside the dialogue choice, a local script

Local Script to add an apple on backpack? You should use a normal script (serverscript).
Local scripts are not working for this type of things.

i meant to say server script, like u have the apple in starterpack, and i want to give it to the npc and its a server sccript

Can you send me screenshot from where’s the script better?

Screenshot 2024-09-03 at 10.08.16 PM

Bro but show me if it is on workspace or something…? That’s what we are talking about


this is what u need?

Yea, ok, can you try to move the script like to workspace and make it work from there?

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)

wait i figured whats wrong gimme a minute

Lol I was going to ask u to send me download

nvm still doesnt work do u know what to fix

Send me download of the dummy and apple and I should check

I saw what’s the problem, just giveme a few minutes to fix it

The issue is that you’re trying to detect an event that can only be used on the clientside in the serverside.

dialog.DialogChoiceSelected cannot be read on the server. You must run it in a local script.

i have to go out somewhere for a couple of hours ( more than 12h ) ill be back later to check