generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: attempt to compare two table values

Previous Thread :: Next Thread 
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
05 Nov 2016 03:24 PM
Use my example on another forum of sorting the players by their stats
Report Abuse
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
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
expoundings is online. expoundings
Joined: 02 Feb 2013
Total Posts: 2359
05 Nov 2016 03:25 PM
you can't sort tables inside a table.......
Report Abuse
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
05 Nov 2016 03:26 PM
AHA
AHAHAHAHAHAHAHA
THANK YOU
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
05 Nov 2016 03:28 PM
Sort it with

function(a,b)
return a[2 ]>b[2 ]
end

as your comp
Report Abuse
expoundings is online. expoundings
Joined: 02 Feb 2013
Total Posts: 2359
05 Nov 2016 03:28 PM
instead of
table.insert(Monies,{player.Name,money.Value})
try
Monies[player.Name] = money.Value
Report Abuse
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
05 Nov 2016 03:29 PM
^ won't sort it

Dictionaries cannot be sorted any other way as they have no order
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
05 Nov 2016 03:37 PM
You still did not use my function
Stop trying to change it
Report Abuse
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image