How do I check for a specific item in a player's inventory?

I want to only allow players that have a specific item to be able to do something, but I don’t know how to check for that item.
I’ve attempted some code, but it just doesn’t do anything. If you click, nothing happens, if you click with the item that’s supposed to work, nothing happens.
Here’s the code:


Thanks for your help!

The variable Find stays constant since its defined before the function, if you put line 5 in the function then it might work

Like this?


I tried it like this and it still didn’t work, sorry if you meant another way.

Does the function run like does it print no pancake in the output?

Nothing prints at all, nothing about the script prints.

Oh then can u check if anything prints right after the backpack variable? I think it might be yielding the code

Does the click function work? Add a print statement inside it to make sure it’s running. Is the script inside a proper object and not part of Roblox Core? Also, the variable for ‘Backpack’ seems incorrect. You need to reference the player’s ‘Backpack’ instead of creating your own variable, otherwise it’s not going to work.

Somethings prints at the backpack variable, it says “Script ‘Workspace.BlueberryMachine.Button.Tool Name Here!!!’, Line 4 - Studio - Tool Name Here!!!:4”
After that, nothing shows up about the script.

Before I tried to add the finding function, it did work and give me the item.

nvm nvm my bad can you send me the cscrript ?

So like local Backpack = plr.backpack instead of what it was?

local tool = game.ServerStorage["Blueberry Pancake"] local clone = tool:clone() local player = game.Players.LocalPlayer local Backpack = player:WaitForChild("Backpack") script.Parent.ClickDetector.MouseClick:connect (function(plr) local Find = player.Backpack:FindFirstChild("Stove Pancake") if Find then script.Parent.Parent.BlueberryPlainP.P1.Transparency = 0 script.Parent.Parent.BlueberryPlainP.P2.Transparency = 0 script.Parent.Parent.BlueberryPlainP.P3.Transparency = 0 if clone.Parent ~= plr.Backpack then wait(3) script.Parent.Parent.BlueberryPlainP.P1.Transparency = 1 script.Parent.Parent.BlueberryPlainP.P2.Transparency = 1 script.Parent.Parent.BlueberryPlainP.P3.Transparency = 1 script.Parent.Parent.BlueberryPancake.P1.Transparency = 0 script.Parent.Parent.BlueberryPancake.P2.Transparency = 0 script.Parent.Parent.BlueberryPancake.P3.Transparency = 0 script.Parent.Parent.BlueberryPancake.Butter.Transparency = 0 script.Parent.Parent.BlueberryPancake.Syrup.Transparency = 0.55 wait(2) clone.Parent = plr.Backpack script.Parent.Parent.BlueberryPancake.P1.Transparency = 1 script.Parent.Parent.BlueberryPancake.P2.Transparency = 1 script.Parent.Parent.BlueberryPancake.P3.Transparency = 1 script.Parent.Parent.BlueberryPancake.Butter.Transparency = 1 script.Parent.Parent.BlueberryPancake.Syrup.Transparency = 1 wait(5) else end else print('no pancake') end end)

variable of find , change to plr instead of player , and variable of backpack need to use inside function and change to plr too

Should I change local player to local plr also?

So like


?

After the click detector has been clicked does it print anything? If it does then which code does it end up running, the code after line 7 or the code after line 31?

You don’t need to use LocalPlayer; the script doesn’t know who’s clicking. The only way for it to know is through the function’s parameter, which will identify who is clicking. I assume this is a server-side script since you’re using ServerStorage.

Nothing prints after clicking it.

Should I do something instead of LocalPlayer then?

local tool = game.ServerStorage["Blueberry Pancake"]
local clone = tool:Clone()

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	local playerBackpack = plr:WaitForChild("Backpack")
	local find = playerBackpack:FindFirstChild("Stove Pancake")

	if find then
		script.Parent.Parent.BlueberryPlainP.P1.Transparency = 0
		script.Parent.Parent.BlueberryPlainP.P2.Transparency = 0
		script.Parent.Parent.BlueberryPlainP.P3.Transparency = 0

		if clone.Parent ~= playerBackpack then
			wait(3)

			script.Parent.Parent.BlueberryPlainP.P1.Transparency = 1
			script.Parent.Parent.BlueberryPlainP.P2.Transparency = 1
			script.Parent.Parent.BlueberryPlainP.P3.Transparency = 1
			script.Parent.Parent.BlueberryPancake.P1.Transparency = 0
			script.Parent.Parent.BlueberryPancake.P2.Transparency = 0
			script.Parent.Parent.BlueberryPancake.P3.Transparency = 0
			script.Parent.Parent.BlueberryPancake.Butter.Transparency = 0
			script.Parent.Parent.BlueberryPancake.Syrup.Transparency = 0.55

			wait(2)
			clone.Parent = playerBackpack
			script.Parent.Parent.BlueberryPancake.P1.Transparency = 1
			script.Parent.Parent.BlueberryPancake.P2.Transparency = 1
			script.Parent.Parent.BlueberryPancake.P3.Transparency = 1
			script.Parent.Parent.BlueberryPancake.Butter.Transparency = 1
			script.Parent.Parent.BlueberryPancake.Syrup.Transparency = 1

			wait(5)
		end
	else
		print("Error")
	end
end)
1 Like