File size: 3,593 Bytes
0712d5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
-- src/ServerScriptService/LeaderboardManager.server.lua

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local GameConfig = require(ReplicatedStorage:WaitForChild("Shared"):WaitForChild("GameConfig"))

-- Create global leaderboard SurfaceGui on a part in the world
local leaderboardFolder = Instance.new("Folder")
leaderboardFolder.Name = "Leaderboard"
leaderboardFolder.Parent = workspace

local function createLeaderboardDisplay()
	local board = Instance.new("Part")
	board.Name = "LeaderboardBoard"
	board.Size = Vector3.new(12, 8, 0.5)
	board.Position = Vector3.new(-10, 8, -80)
	board.Anchored = true
	board.Material = Enum.Material.SmoothPlastic
	board.BrickColor = BrickColor.new("Really black")
	board.Parent = leaderboardFolder

	local surfaceGui = Instance.new("SurfaceGui")
	surfaceGui.Name = "LeaderboardGui"
	surfaceGui.Face = Enum.NormalId.Front
	surfaceGui.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
	surfaceGui.PixelsPerStud = 50
	surfaceGui.Parent = board

	-- Title
	local title = Instance.new("TextLabel")
	title.Name = "Title"
	title.Size = UDim2.new(1, 0, 0.15, 0)
	title.Position = UDim2.new(0, 0, 0, 0)
	title.BackgroundColor3 = Color3.fromRGB(40, 80, 40)
	title.BorderSizePixel = 0
	title.Text = "TOP LUMBERJACKS"
	title.TextColor3 = Color3.new(1, 1, 1)
	title.TextScaled = true
	title.Font = Enum.Font.GothamBold
	title.Parent = surfaceGui

	-- Entries container
	local entriesFrame = Instance.new("Frame")
	entriesFrame.Name = "Entries"
	entriesFrame.Size = UDim2.new(1, 0, 0.85, 0)
	entriesFrame.Position = UDim2.new(0, 0, 0.15, 0)
	entriesFrame.BackgroundColor3 = Color3.fromRGB(20, 20, 20)
	entriesFrame.BorderSizePixel = 0
	entriesFrame.Parent = surfaceGui

	local listLayout = Instance.new("UIListLayout")
	listLayout.SortOrder = Enum.SortOrder.LayoutOrder
	listLayout.Parent = entriesFrame

	return entriesFrame
end

local entriesFrame = createLeaderboardDisplay()

local function updateLeaderboard()
	-- Clear existing entries
	for _, child in pairs(entriesFrame:GetChildren()) do
		if child:IsA("TextLabel") then
			child:Destroy()
		end
	end

	-- Collect player data
	local playerStats = {}
	for _, player in ipairs(Players:GetPlayers()) do
		local leaderstats = player:FindFirstChild("leaderstats")
		if leaderstats then
			local cash = leaderstats:FindFirstChild("Cash")
			if cash then
				table.insert(playerStats, {
					name = player.Name,
					cash = cash.Value,
				})
			end
		end
	end

	-- Sort by cash descending
	table.sort(playerStats, function(a, b) return a.cash > b.cash end)

	-- Display top 10
	local maxEntries = math.min(#playerStats, 10)
	for i = 1, maxEntries do
		local entry = Instance.new("TextLabel")
		entry.Name = "Entry_" .. i
		entry.Size = UDim2.new(1, 0, 0, 30)
		entry.LayoutOrder = i
		entry.BackgroundTransparency = 0.5
		entry.BackgroundColor3 = i % 2 == 0 and Color3.fromRGB(30, 30, 30) or Color3.fromRGB(40, 40, 40)
		entry.BorderSizePixel = 0
		entry.Text = string.format("  #%d  %s  -  $%s", i, playerStats[i].name, tostring(playerStats[i].cash))
		entry.TextColor3 = i == 1 and Color3.fromRGB(255, 215, 0) or Color3.new(1, 1, 1)
		entry.TextXAlignment = Enum.TextXAlignment.Left
		entry.TextScaled = true
		entry.Font = Enum.Font.GothamMedium
		entry.Parent = entriesFrame
	end
end

-- Update periodically
task.spawn(function()
	while true do
		updateLeaderboard()
		task.wait(15)
	end
end)

print("Leaderboard Manager initialized")