-- vf as votes folder
local table_example = {vf.Crossroads, vf.HappyHome, vf.HQ}
the issue is that i getting “nil” instead or “” (suggesting its same to nil)
the sorting calculation was nearly:
local table_example = {vf.Crossroads, vf.HappyHome, vf.HQ}
local vts = table.sort(table_example , function(a,b) return a.Value>b.Value end)
depending on result of sorted table script was taking first object in sorted table and putting map from replicated storage with vts[1].Name BUT i was getting error “attempt to index nil with number” after trying do same operation in console, i was also getting nil and im just like really stuck here.
Your understanding of the function is wrong. You think that you pass in a table, it creates a copy that is sorted, then returns said copy. However the table.sort function sorts the original table you pass in it, and thus it doesn’t need to return anything. To receive the sorted table all you have to do is wait for the function to finish running before checking the table you passed in(since it yields the code):
local t = {6, 2, 7, 4, 8, 1, 9, 3}
table.sort(t)
print(t) --should be sorted
since the function tampers with the table you pass in, this means that if you want to keep the original table, you will have to first copy it:
local t = {} --the unsorted table
local sorted = table.clone(t) --not sorted yet, but we will store the sorted table here
table.sort(sorted) --now we sort
print(t, sorted) --should print the original and the sorted table
Lastly keep in mind that the table.clone function shallow copies the table, so if the original table had nested tables inside, and you change them, they will also change in the sorted version. If you want to create a completely unrelated table, you will have to deep copy, deep copying is a recursive process of cloning a table and the sub-tables it has.