How do you make a leaderboard GUI with the cash/points in it?

  1. What do you want to achieve? I want to make a custom leaderstats gui with the list of players with the amount of cash/points the player has. And I just want to make it mobile friendly(mobile players can’t see leaderstats.)

  2. What is the issue? None, actually, I just want to make a gui with a list of players and amount of the player’s cash.

  3. What solutions have you tried so far? Tried to look on YouTube but no one makes tutorials on my problem.

Edit: Here’s the script:
Leaderstats:

local DataStore = game:GetService("DataStoreService"):GetDataStore("ValueSave")

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder", plr)
	leaderstats.Name = "leaderstats"

	local Bucks = Instance.new("IntValue", leaderstats)
	Bucks.Name = "Bucks"
	Bucks.Value = DataStore:GetAsync(plr.userId) or 0
	Bucks.Changed:Connect(function()
		DataStore:SetAsync(plr.userId, Bucks.Value)
	end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	DataStore:SetAsync(plr.userId, plr.leaderstats.Bucks.Value)
end)



Just add a GUI then put a local script in it. The script would look like this: (BTW the script in this situation is inside of the text label being changed.)

plr = game.Players.LocalPlayer
stat = Cash
while wait(0.1) do
script.Parent.Text = "Cash: "..plr.leaderstats[stat].Value
end

EDIT: I didn’t read the entire thing, this is just a script that tells the player what their stats are not like a custom leaderboard, that’s too advanced for me.

1 Like

You should be providing the script already. This is scripting support

Your code is inefficient, a loop isn’t good practice when it comes to updating value changes. Instead use Changed or GetPropertyChangedSignal

1 Like

Just add a GUI then put a local script in it.

plr = game.Players.LocalPlayer
stat = Cash
while wait(0.1) do
script.Parent.Text = "Cash: "…plr.leaderstats[stat].Value
end

1 Like

If I’m understanding correctly, the previous replies are wrong. If you want to get the leaderstats of each player, you can iterate through Players:GetPlayers() and create a GetPropertyChangedSignal event for each of them.

Here’s what the iteration would look like, but make sure to update this when a player joins/leaves as well.

for _, plr in pairs (game:GetService("Players"):GetPlayers() do
     local leaderstats = plr:WaitForChild("leaderstats", 1)
     if leaderstats then
          local frame = template:Clone() -- Template would be an invisible frame that is a template for a slot on your leaderboard. You can organize them easily using a UIGridLayout.
          frame.Username.Text = plr.Name
          frame.Stat.Text = leaderstats.Cash.Value
          frame.Visible = true
          frame.Parent = template.Parent
          leaderstats.Cash:GetPropertyChangedSignal("Value"):Connect(function()
               frame.Stat.Text = leaderstats.Cash.Value
          end)
     end
end

I don’t think there would be a need to perform manual garbage collection for the GetPropertyChangedSignal event because it would automatically be disconnected when the player leaves (therefore the frame would be destroyed with the PlayerRemoving event that you’ll add), but I could be wrong.

2 Likes

But where do i put this script?

He wants to have leaderboard with all players cash :wink:

1 Like

Oh, then StarterPlayerScripts.

1 Like