NPC Quest system not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to achieve a quest system that can be completed once giving an NPC 4 items.
  2. What is the issue? Include screenshots / videos if possible!
    The issue is that even though I am holding the item, the script just ignores it and doesn’t think I am holding the item.

Here is the code

GiveNugget.Triggered:Connect(function(player)
	local Tool = player.Backpack:FindFirstChild("Nugget") 
	if player.Backpack:FindFirstChild("Nugget") or player.Character:FindFirstChild("Nugget") then
		nuggetCounter += 1
		print(nuggetCounter)
		if nuggetCounter == 4 then
			print("Done")
			textLabel.Parent.CharacterName.Text = "Terry"
			ProximityPrompt.Enabled = false
			typewrite(textLabel, "thanks, here's some beans")
			wait(2)
			typewrite(textLabel, " ")
			local ReplicatedStorage = game:GetService("ReplicatedStorage")

			local Tool = ReplicatedStorage.Tools["Beans"]:Clone()

			for _,v in pairs(player.Character:GetChildren()) do
				if v:IsA("Tool") then
					print("Didn't pick up the tool! Inventory full")
				end
			end

			for _,v in pairs(player.Backpack:GetChildren()) do
				if v:IsA("Tool") then
					print("Didn't pick up the tool! Inventory full")
				end
			end

			if #player.Backpack:GetChildren() == 0 then
				Tool.Parent = player.Backpack
				script.Parent:Destroy()
			end
		end
	else
		print("Player doesn't have nugget")
	end
end)

It just prints “Player doesn’t have nugget” even if I have a nugget

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have looked on the DevForum and tweaked my code for different results.

This is my first post so please let me know if I am doing anything wrong or if it’s not clear enough

1 Like

First things first here’s a safer way to check:

local Tool = player.Backpack:FindFirstChild("Nugget") or player.Character:FindFirstChild("Nugget")
if Tool then --before the "Tool" variable was untrue as it would only check in the backpack
	print("Player has a nugget!")
end

Now here’s a question, do you give the nugget tool in a local or server script? and is this script you sent in a local or server script?

1 Like

Both scripts are local scripts

Oh wait I just figured it out thanks! The script deleted the tool before the other script could tell if it had the tool.

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