KZskychi
|
  |
| Joined: 19 Apr 2012 |
| Total Posts: 202 |
|
|
| 10 May 2017 03:40 AM |
Alright, so I have this script below:
for _, players in pairs (game.Players:GetPlayers()) do local pistol = game.ServerStorage.Pistol:Clone() pistol.Parent = v:WaitForChild('Backpack') end
What I want to find out is, In 60 seconds, which player has the largest amount of points.
The leaderboard is in the player like this: Player.leaderstats.Points
How do I find this out? |
|
|
| Report Abuse |
|
|
|
| 10 May 2017 03:43 AM |
local p = game.Players:GetPlayers()
table.sort(p,function(a,b) return a.leaderstats.Points.Value > b.leaderstats.Points.Value end)
local player = p[1]
|
|
|
| Report Abuse |
|
|
KZskychi
|
  |
| Joined: 19 Apr 2012 |
| Total Posts: 202 |
|
|
| 10 May 2017 03:47 AM |
| I have more than 2 players in the game. |
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
rankyn2
|
  |
| Joined: 29 Dec 2016 |
| Total Posts: 40 |
|
| |
|
Cyrakohl
|
  |
| Joined: 09 Nov 2014 |
| Total Posts: 3197 |
|
| |
|
RogueMage
|
  |
| Joined: 28 Jan 2012 |
| Total Posts: 1235 |
|
|
| 10 May 2017 11:06 AM |
| OP, That function he used in the table sorts players from largest to smallest based ## ##### ####### the sort function could take an argument of a function that allows you to compare two values and return the one that's larger (or the one you want to go first) Does that explain it? |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 10 May 2017 11:39 AM |
| local players = game.Players:GetPlayers() table.sort(players,function(player1,player2) return ################################ > ################################ end) for i,v in next, players do print(v,'is player number',i) end |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 10 May 2017 11:42 AM |
i give up on this filter fr
|
|
|
| Report Abuse |
|
|
|
| 10 May 2017 12:17 PM |
I normally define the comparator outside.
function compareTo(a, b) return (a.leaderstats.Points.Value > b.leaderstats.Points.Value) end
local p = game.Players:GetPlayers() table.sort(p, compareTo) print(p[1].Name.." has the most points") |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 10 May 2017 02:13 PM |
If you just want the player with the most points, DO NOT USE TABLE.SORT. Just iterate over the table and record who has the highest. |
|
|
| Report Abuse |
|
|