Help with attributes

local lootables = game.Workspace.Lootables
local objects = {} 

for count, instance in pairs(game.Workspace.Lootables:GetChildren()) do
	table.insert(objects, instance)
	local weaponAttributes = instance:GetAttributes()
	for name, value in pairs(weaponAttributes) do
		print(name, value)
	end	
	if weaponAttributes.name == "loottable" then
		instance:Destroy()
	end

		
end

the part below is what i’m trying to achieve, it is supposed to destroy the trashcan (for testing purposes) but it does not. anyone know why?

if weaponAttributes.name == "loottable" then
		instance:Destroy()
	end
1 Like

It’s probably not a good idea to use an attribute that is similar to a built-in property name, Name. It might be better to name a boolean attribute “Lootable” and/or use another boolean attribute “DestroyDuringTest” or similar. Then you can act on those attributes individually:

for count, instance in pairs(game.Workspace.Lootables:GetChildren()) do
    if instance:GetAttribute("Lootable") then
        -- ...
    end
end
2 Likes