|
| 05 Nov 2016 03:23 PM |
local playerfolder = game.ServerStorage:WaitForChild("Players")
local Monies = {}
for _,player in pairs(playerfolder:GetChildren()) do local money = player:FindFirstChild("Money") table.insert(Monies,{player.Name,money.Value}) end
table.sort(Monies)
for _,v in pairs(Monies) do print(v[1],v[2]) end
Trying to use soybeen's script to compare the values but the sort line errors (attempt to compare two table values). What's wrong and how do I fix it? |
|
|
| Report Abuse |
|
|
|
| 05 Nov 2016 03:24 PM |
| Use my example on another forum of sorting the players by their stats |
|
|
| Report Abuse |
|
|
|
| 05 Nov 2016 03:25 PM |
| This isn't for players though. I just kept his variables bcuz I'm lazy. Thanks anyway. |
|
|
| Report Abuse |
|
|
|
| 05 Nov 2016 03:25 PM |
| you can't sort tables inside a table....... |
|
|
| Report Abuse |
|
|
|
| 05 Nov 2016 03:26 PM |
AHA AHAHAHAHAHAHAHA THANK YOU |
|
|
| Report Abuse |
|
|
|
| 05 Nov 2016 03:28 PM |
Sort it with
function(a,b) return a[2 ]>b[2 ] end
as your comp |
|
|
| Report Abuse |
|
|
|
| 05 Nov 2016 03:28 PM |
instead of table.insert(Monies,{player.Name,money.Value}) try Monies[player.Name] = money.Value |
|
|
| Report Abuse |
|
|
|
| 05 Nov 2016 03:29 PM |
Now I have:
local playerfolder = game.ServerStorage:WaitForChild("Players")
local Monies = {}
for _,player in pairs(playerfolder:GetChildren()) do local money = player:FindFirstChild("Money") table.insert(Monies,player.Name,money.Value) end
table.sort(Monies)
for _,v in pairs(Monies) do print(v[1],v[2]) end
And on the insert line it says "bad argument #2 to 'insert' (number expected, got string)" Can the index not be a string? |
|
|
| Report Abuse |
|
|
|
| 05 Nov 2016 03:29 PM |
^ won't sort it
Dictionaries cannot be sorted any other way as they have no order |
|
|
| Report Abuse |
|
|
|
| 05 Nov 2016 03:29 PM |
| Intended, leave it as it was before but use my function as comp for the table sorting |
|
|
| Report Abuse |
|
|
|
| 05 Nov 2016 03:35 PM |
Still has the same error:
local playerfolder = game.ServerStorage:WaitForChild("Players")
local Monies = {}
for _,player in pairs(playerfolder:GetChildren()) do local money = player:FindFirstChild("Money") table.insert(Monies,{player.Name,money.Value}) end
table.sort(Monies,function(a,b) return a>b end)
for _,v in pairs(Monies) do print(v[1],v[2]) end
|
|
|
| Report Abuse |
|
|
|
| 05 Nov 2016 03:37 PM |
You still did not use my function Stop trying to change it |
|
|
| Report Abuse |
|
|
|
| 05 Nov 2016 03:39 PM |
I'm sorry Wunder, I was confused. Thank you so much, I did figure it out!
local playerfolder = game.ServerStorage:WaitForChild("Players")
local Monies = {}
for _,player in pairs(playerfolder:GetChildren()) do local money = player:FindFirstChild("Money") table.insert(Monies,{player.Name,money.Value}) end
table.sort(Monies, function(a,b) return a[2 ]>b[2 ] end)
for _,v in pairs(Monies) do print(v[1],v[2]) end |
|
|
| Report Abuse |
|
|