local function GetInstance(Folder)
local InstanceArray = InstanceArray:GetChildren()
local RandomInstance = InstanceArray[math.random(1, #InstanceArray)]
return RandomInstance
end
However, I tried the same method, but to get a random Attribute.
local function GetAttribute(Folder)
local Attributes = Folder:GetAttributes()
local RandomAttribute = Attributes[math.random(1, #Attributes)]
return RandomAttribute
end
The attribute name is cast to a string so the “1” is actually a string and not a number so #Attributes will always return 0. You can loop through the attributes and add them to a numerical index array.
GetAttributes returns a dictionary, not an array. The # operator can only be used on arrays. This means that it will return a value of 0, because Attributes is a dictionary. To get the number of items in a dictionary, loop through it with a counter variable.
local Attributes = Folder:GetAttributes()
local AttributesArray = {}
for i, v in pairs(Attributes) do
table.insert(AttributesArray, v)
end
print(AttributesArray[math.random(#AttributesArray)])