How to find a tool with name and attribute?

Well, I thought that by “calling” the tool in a way, it would work. However, it gives me an error: Workspace.Cocina.Cocina.MuebleInferior.Part.Script:146: attempt to call a nil value

local Tool = Backpack:FindFirstChild(Slot[2].Name) and Backpack[Slot[2].Name].Name:GetAttribute("Type_Tool", "IngredientJob")

if Tool ~= nil then
	Tool.Stack.Value = Tool.Stack.Value + 1	
end

I think it’s because of the Slot[] that may be wrong.

No, I checked and it’s okay. The problem I think comes from trying to get the attribute

:GetAttribute only needs one parameter though that being the name, and returns the variable inside the attribute.

Assuming Backpack[Slot[2].Name] is an instance, you are trying to call :GetAttribute() on a string since you also put .Name outside the brackets. Try removing the last .Name.

1 Like

I think you meant this?

local Tool = Backpack:FindFirstChild(Slot[2].Name) and Backpack[Slot[2]].Name:GetAttribute("Type_Tool", "IngredientJob")

You were getting the name, then getting the name again. That may fix it, I’m not 100% sure though.

I certainly didn’t notice that detail. It no longer gives me the error, but now the tool does not detect me, it detects the attribute. I mean, I put print and it gives me “IngredientJob”

local Tool = Backpack:FindFirstChild(Slot[2].Name) and Backpack:FindFirstChild(Slot[2].Name):GetAttribute("Type_Tool", "IngredientJob")

if Tool ~= nil then
	print(Tool)
	Tool.Stack.Value += 1
end

This is because the variable takes the second value and checks if the first value is not nil/is true. You will have to do a separated statement for what you’re trying to achieve.

local Tool = Backpack:FindFirstChild(Slot[2].Name)

if Tool and Tool:GetAttribute("Type_Tool", "IngredientJob") then
	print(Tool)
	Tool.Stack.Value += 1
end