Well, I’m trying to ensure that if there is no tool with the “IngredientJob” attribute, the condition is met. Trying to do this I get the following error: attempt to index nil with 'GetAttribute'
elseif not character:FindFirstChild(SelectedObject):GetAttribute("Type_Tool") == "IngredientJob" then
print("True")
end
Yes. Maybe, if you don’t have any tool and you activate the function, when trying to find the tool, it gives the error because there is no tool that can collect the attribute
local tool = character:FindFirstChild(SelectedObject)
if tool then
local attVal = tool:GetAttribute("Type_Tool")
if attVal == "IngredientJob" then
--stuff here
end
else
--stuff here
end
You should be doing this in parts to mitigate the risk of errors. Your error was occurring because you were calling the instance method :GetAttribute() through a nil value (when the tool wasn’t found in the player’s character).