Problem with table,find()

Hello,
I was triying to use table.find() to get the number of an element in this table

module.AccesoryTypesArray = {
	[1] = "Image",
	[2] = "TShirt",
	[3] = "Audio",
	[4] = "Mesh",
	[5] = "Lua",
	[8] = "Hat",
	[9] = "Place",
	[10] = "Model",
	[11] = "Shirt",
	[12] = "Pants",
	[13] = "Decal",
	[17] = "Head",
	[18] = "Face",
	[19] = "Gear",
	[21] = "Badge",
	[24] = "Animation",
	[27] = "Torso",
	[28] = "RightArm",
	[29] = "LeftArm",
	[30] = "LeftLeg",
	[31] = "RightLeg",
	[32] = "Package",
	[34] = "GamePass",
	[38] = "Plugin",
	[40] = "MeshPart",
	[41] = "HairAccessory",
	[42] = "FaceAccessory",
	[43] = "NeckAccessory",
	[44] = "ShoulderAccessory",
	[45] = "FrontAccessory",
	[46] = "BackAccessory",
	[47] = "WaistAccessory",
	[48] = "ClimbAnimation",
	[49] = "DeathAnimation",
	[50] = "FallAnimation",
	[51] = "IdleAnimation",
	[52] = "JumpAnimation",
	[53] = "RunAnimation",
	[54] = "SwimAnimation",
	[55] = "WalkAnimation",
	[56] = "PoseAnimation",
	[57] = "EarAccessory",
	[58] = "EyeAccessory",
	[61] = "EmoteAnimation",
	[62] = "Video",
	[64] = "TShirtAccessory",
	[65] = "ShirtAccessory",
	[66] = "PantsAccessory",
	[67] = "JacketAccessory",
	[68] = "SweaterAccessory",
	[69] = "ShortsAccessory",
	[70] = "LeftShoeAccessory",
	[71] = "RightShoeAccessory",
	[72] = "DressSkirtAccessory",
	[73] = "FontFamily",
	[76] = "EyebrowAccessory",
	[77] = "EyelashAccessory",
	[78] = "MoodAnimation",
	[79] = "DynamicHead"
}

(Asset Types Ids) And when I try to find assets wich’s number is less of 5, ir returns me nil. Examples:

print(table.find(require(game.ReplicatedStorage.MainModule).AccesoryTypesArray, "Hat"))-->nil

image

print(table.find(require(game.ReplicatedStorage.MainModule).AccesoryTypesArray, "BackAccessory"))-->nil

image
I readed the documentation of the table.find() functions and I think that it should work.
Important: Is not because of the jump of numbers from 5 to 8, I tried filling it and it continue whitout working.
I will thank any help, thanks!

1 Like

Table.find only works for tables, not arrays. When assigning number values to a value, you automatically make it an array. Remove the numbers and you’ll be fine. If not, you can just use a for loop, which is literally what table.find does.

local function module.find(input) 
for i,v in pairs(module.AccessoryTypesArray) do
   if v == "input" then
       print(i)
   end
end
end

Be careful when reading documentation as I’ve found that roblox engineers seem to mix up table and array terms.

Table: A list of values
Array: A list of values assigned to an index. (Can be things other than numbers)

1 Like

Ok, thanks, I will be more carefull while reading Lua documentation.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.