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
 

Leaderboard Gui showing the richest player first...

Previous Thread :: Next Thread 
cocoaboys is not online. cocoaboys
Joined: 08 Sep 2013
Total Posts: 488
17 Jul 2017 07:18 PM
Hey, I just made a Leaderboard Gui which goes through the array game.Players:GetChildren(), and generates a leaderboard from that. But I want the richest person to be at the top, then the next richest person and so on... Their money is defined in a NumberValue stored inside a Folder -> game.Players.cocoaboys.Folder.Money.Value...
I used this kind of for-loop to generate the leaderboard:

for i, v in pairs (game.Players:GetChildren()) then

... code ...

end

... but how do I start with the richest one, and so on??
Report Abuse
cocoaboys is not online. cocoaboys
Joined: 08 Sep 2013
Total Posts: 488
17 Jul 2017 07:25 PM
I'm making a TextLabel for each player, so i want to define an array before the loop fires, and then pushes the richest player into the array, then the next richest, and so on...
Report Abuse
cocoaboys is not online. cocoaboys
Joined: 08 Sep 2013
Total Posts: 488
17 Jul 2017 07:31 PM
Sorry this was very goofy explained, lol
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
17 Jul 2017 07:35 PM
local players

table.sort(players, function(player1, player2)
return player1.leaderstats.Value.Value > player2.leaderstats.Value.Value
end)


Report Abuse
cocoaboys is not online. cocoaboys
Joined: 08 Sep 2013
Total Posts: 488
17 Jul 2017 07:43 PM
Thanks! So if I have table declared as an empty variable, this function inserts the players from high to low money value?
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
17 Jul 2017 07:47 PM
I only made the variable empty because I didn't know for sure how the players were going to be obtained.


Report Abuse
cocoaboys is not online. cocoaboys
Joined: 08 Sep 2013
Total Posts: 488
17 Jul 2017 07:52 PM
Oooh I see, well I run an infinite while-loop every second, where I declare this: local players = game.Players:GetChildren(). Your sorting method will save as the local players, only in sorted order from high to low cash?
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
17 Jul 2017 07:57 PM
Don't run table.sort in an infinite loop multiple times a second like that. It's expensive.

You only need to update the leaderboard when:

1) Someone/everyone is awarded points
2) Someone joins/leaves


Report Abuse
cocoaboys is not online. cocoaboys
Joined: 08 Sep 2013
Total Posts: 488
17 Jul 2017 08:01 PM
Yeah, hmmm. I need to use RemoteEvents for that first one..
Report Abuse
cocoaboys is not online. cocoaboys
Joined: 08 Sep 2013
Total Posts: 488
17 Jul 2017 08:05 PM
I could do this:
Every player have a LocalScript in their StarterPlayerScriots, which fires a script through a RemoteEvent everytime their points changes. Then that script would fire all clients though another remoteevent, where every playergui is updated. Seems good?
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
17 Jul 2017 08:07 PM
That seems fine. You really don't even need to use table.sort unless you're lazy; when PlayerAdded is invoked, you just need to iterate through players' values and insert the new player in the leaderboard accordingly. With PlayerRemoving you just need to shift all players below the player who left upward.


Report Abuse
cocoaboys is not online. cocoaboys
Joined: 08 Sep 2013
Total Posts: 488
17 Jul 2017 08:08 PM
And I could just make a script which fires all clients when PlayerAdded or PlayerRemoved happens?
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
17 Jul 2017 08:08 PM
You don't need to. Both events can be handled locally.


Report Abuse
cocoaboys is not online. cocoaboys
Joined: 08 Sep 2013
Total Posts: 488
17 Jul 2017 08:09 PM
Hmm, I think I'll stick to the sortingmethod, so I dont use so many different functions.
Report Abuse
cocoaboys is not online. cocoaboys
Joined: 08 Sep 2013
Total Posts: 488
17 Jul 2017 08:10 PM
################ I forgot to say that I have enabled FilteringEnabled
Report Abuse
cocoaboys is not online. cocoaboys
Joined: 08 Sep 2013
Total Posts: 488
17 Jul 2017 08:15 PM
Really? How can I handle the first one locally?
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
17 Jul 2017 08:19 PM
I mean, it's a leaderboard. You can handle the whole thing locally; if the client wants to mess with their leaderboard, let them. Why the hell would it matter to anyone? It's not like they're changing any important values.

My point is, a leaderboard is just a projection of values that only the server can touch.


Report Abuse
cocoaboys is not online. cocoaboys
Joined: 08 Sep 2013
Total Posts: 488
17 Jul 2017 08:21 PM
Yeah, FilteringEnabled only cause problems when the client tries to manipulate something the server can access.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
17 Jul 2017 08:21 PM
I don't see that as a problem :)


Report Abuse
cocoaboys is not online. cocoaboys
Joined: 08 Sep 2013
Total Posts: 488
17 Jul 2017 08:23 PM
But I have a LocalScript inside every player's StarterPlayerScripts, and how to I fire the function inside every player's LocalScript when # ##################### ###### changes?
Report Abuse
cocoaboys is not online. cocoaboys
Joined: 08 Sep 2013
Total Posts: 488
17 Jul 2017 08:25 PM
Hashtags: when someone's points changes*
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
17 Jul 2017 08:28 PM
Locally:

local players = game:GetService("Players")

-- Handle value changes for players that don't exist yet
players.PlayerAdded:Connect(function(player)
player:WaitForChild("leaderstats"):WaitForChild("Value").Changed:Connect(function(value)
print("New value for player", player .. ":", value)
end)
end)

-- Handle value changes for those who currently exist
for _, player in pairs(players:GetPlayers()) do
-- You probably get the point by now
end


Report Abuse
cocoaboys is not online. cocoaboys
Joined: 08 Sep 2013
Total Posts: 488
17 Jul 2017 08:33 PM
Aaaah you fuse them together! I would propably refer to a guiChange function where the print is. But would that changed-function work continously? What I was thinking at first is that it only will fire 1 time - when the player joins..?
Report Abuse
cocoaboys is not online. cocoaboys
Joined: 08 Sep 2013
Total Posts: 488
17 Jul 2017 08:34 PM
But ithe change-function will fire every single time a player's points changes, right?
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
17 Jul 2017 08:35 PM
The Changed event will continue to be invoked until the player leaves. So no, it won't fire only once (unless the player's points are only changed once).


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 2Go to page: [1], 2 Next
 
 
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