module.SearchTable = function(Table,ObjectToFind)
for i,v in pairs(Table) do
if v == obj then
return i[v]
end
end
end
Would this return the position of it in the table? Im not sure so I though Id ask.
Example of my use case:
local NPCs = {workspace.NPC,workspace.NPC2}
local newNpc = NPC3:Clone()
newNpc.Parent = workspace
table.insert(NPCs,(#NPCs + 1),newNpc)
local tablePosition = module.Search(NPCs, newNPC)
I could have a number of NPCs in that table, it isn’t limited to 3. This is why if I add multiple at once, I want to be able to get its position in the table (i.e NPCs[1], NPCs[2])
Use table.find(array, valueToFind), it returns the position of the found value, or nil if nothing’s found. Keep in mind that it’s faster than using lua to find a value in a table, and it only works on arrays.
Oh, awesome! So this should return something like NPCs[PositionInArray]? I’ll make sure to test this once Im finished with online classes, thanks a ton.