How would I sort a table like this?
Skibidi?
Well, you see here, this very sigma table can be sorted with the totally goated function table.sort() function!
just a normal table.sort? I thought it sorted depending on the index (which in this case is a string)
please don’t tell me this is a toilet tower defense related game
the table was just an example lol. It’s unrelated to skibidi toilet and brainrot
I’m checking this right now.
But in the meantime, do you want to sort them by NAME order, or VALUE order?
I’d like to sort the value.
this is what a normal table.sort got me
You cannot sort a dictionary. The entry order is not something you can really control. If you wanted to sort this for display, your best bet is converting it to a normal table with a table inside.
(Not formatted well as devforum can’t tab on-site)
local playerVoted = {
["skibidi"] = 40,
["hello"] = 50
}
local newTab = {}
for k,v in playerVoted do
table.insert(newTab,{k,v})
end
newTab:sort(function(a, b)
return a[2] > b[2]
end)
Then you can iterate that table and get entry[1] for the name.
Sorting it sorts it by NAME order, not value order, which I was wrong about earlier.
You could make a new table with the values and sort that
ig i’ll have to remake a lot of my code
welp… that’s sad for me. 3 scripts to change
wait i already have a table like that…
You didn’t follow my instructions there to create a new table. That is why your code does not work. You cannot sort a dictionary.
Your instructions were good. Dw i got it working!