Speaking mainly in the sense of Instance.new(), if the only element needed to be checked for whether or not an object exist in X location, what’s the best object to generate for memory/performance?
Example;
local object = instance.new("Folder")
Object.Name = "Skin1"
Object.Parent = Inventory
if inventory:FindFirstChild("Skin1") then
print(inventory.Skin1)
end
local d = inventory:GetChildren()
for i=1, #d do
if d[i]:IsA("Folder") then
print("folder class detected")
end
end
I’ve seen some just use numbervalues or boolvalues but do those really load in faster than say… a random folder, bindableevent, or empty script object?
If you are looking for the most memory performance and efficiency here, I would use attributes. Attributes vs Values
I believe they are the fastest thing available. You can create them in the properties tab or using a script.
To create one or change its value a script:
inventory:SetAttribute("Skin1") -- First parameter is the name, second parameter is the value (I didnt use a second parameter making the attribute equal to nil
To see if the attribute is there for a check, all you have to do is:
inventory:GetAttribute("Skin1") -- If it's not there it will return nil automatically making it better than FindFirstChild on an object since its faster.
-- You can also set it equal to a variable if you want.
Objects are never as memory/performance efficient compared to the flat and straightforward variables. It is a bad habit to create objects for the sake of verification or data storage for future reference when you can just use tables.
I will use the proper way of scripting your example here so you can compared. Remember that while the script is longer than your example, it’s actually more memory efficient because each object you create have methods, properties, etc when variables by themselves do not.
local inventory = {} -- Reserved
table.insert(inventory, "Skin1")
local location = table.find(inventory, "Skin1")
if location ~= nil then
print(inventory[location])
end
for _, eachSkin in ipairs(inventory) do
-- EXTRA BENEFIT!!! No need to check if something is a folder or not.
print(eachSkin)
end