Custom Leaderboard Displaying All Player Stats

Hey there!
I am trying to make a custom leaderboard gui that displays the leaderstats of all players in the server. I know how to make it display only local player, but how would I do it for all players? Thanks for any and all help!

Sorry if this post seems short. I don’t think there’s much else to say, though. Let me know if you need more info, though. :stuck_out_tongue:

You can use the game.Players:GetPlayers() method which returns a list of all players in the server. You could then loop through them with a for i,v in ipairs(game.Players:GetPlayers()) loop run whatever code you are using to display the stats there.

1 Like

Thanks. But how would I get those text labels to change to show the updated values of each of the other players’ stats whenever they change? I don’t know how to use .Changed in a local script for that.

If you are retrieving other users’ information, you may need to consider using a server script with remote events to update the leaderboard. It might also be useful to show what code you have so far and what the GUI is layed out like.

1 Like

Screenshot (11)
Inside the statchanger local script:

game.ReplicatedStorage.StatChanger.OnClientEvent:Connect(function(player, value)
	if player == script.Parent.Parent.Text then
		script.Parent.Text = script.Parent.Text + value
	end
end)

Inside the playerlist local script:

--< variables

local players = game:GetService("Players")
local frame = script.Parent.Frame
local slots = frame.slots
local temp = frame.Template

local players_table = {}

--< tween info:TweenPosition(endPosition, EasingDirection, EasingStyle, Time, Override)

local dir = "Out"
local style = "Quad"
local dur = 0.5

--< functions

local function cleanup(slot)
	
	-- repeat wait until the slot finishes tweening
	repeat
		wait()
	until slot.Position.X.Offset == 400
	slot:Destroy()
	
end

local function remove(leaving)
	
	-- check if a player is leaving
	if leaving then
	
		-- if so, delete dictionary entry 
		players_table[leaving] = nil
		-- tween player slot out
		local slot = slots:FindFirstChild(leaving)
		slot:TweenPosition(UDim2.new(0, 400, 0, slot.Position.Y.Offset), dir, style, dur, true)
		
		-- delete the slot once it finishes (coroutine)
		local cor = coroutine.wrap(cleanup)
		cor(slot)
		
	end
end

local function add()
	
	-- loop through players
	local chil = players:GetChildren()
	for c = 1, #chil do
	
		-- check if present in dictionary
		if players_table[chil[c].Name] == nil then
				
			-- add to dictionary
			players_table[chil[c].Name] = 1
			
			-- create a slot in the list
			local slot = temp:Clone()
			
				-- edit that slot
			slot.Name = chil[c].Name
			slot.Text = slot.Name
			--slot.stats.Text = chil[c].leaderstats.Money.Value
				slot.Parent = slots
		end
	end
end

local function adjust(leaving)
	
	-- add() and remove()
	add()
	remove(leaving)
	
	local count = 0
	-- loop through players_table
	for key, value in pairs(players_table) do
	count = count + 1
		-- find corresponding slots
		local slot = slots:FindFirstChild(key)
		
		-- tween slot positions
		local ypos = 30 + (25+2)*(count-1)	
		slot:TweenPosition(UDim2.new(0, 0, 0, ypos), dir, style, dur, true)
		
	end			
end

--< events

-- player added event
players.PlayerAdded:connect(function()
	adjust(nil)
end)

-- player removing event
players.PlayerRemoving:connect(function(leaving)
	adjust(leaving.Name)
end)

adjust()