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
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.
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