Global Leaderboard Roblox GUI Template with OrderedDataStore Powered
A top-10 global leaderboard GUI with player name, avatar placeholder, and score. Auto-refreshes every minute. This template provides a production-ready leaderboard system that displays the highest-scoring players across your entire Roblox game. It features a clean, modern design with automatic data synchronization, smooth entry animations, and a responsive layout that works on all screen sizes.

Live preview
Global Leaderboard
1920×1080Includes real, production-ready Luau logic — not a static mockup.
What's inside
- • Top 10 player rows
- • Avatar + name + score columns
- • OrderedDataStore integration stub
- • Auto-refresh timer
- • Mobile scroll support
How to use this template
The Global Leaderboard template shows the top 10 players by score, auto-refreshing every minute. Paste the server Luau into ServerScriptService and the client Luau into StarterGui. The server uses OrderedDataStore to rank players and pushes the top 10 to all clients via a RemoteEvent. The client renders the rows with player name, avatar placeholder, and score. The layout uses UIListLayout so rows stack cleanly and scroll on mobile. To customize, replace the score key with your own stat (coins, wins, level). The auto-refresh interval is configurable in the server Luau. Note that OrderedDataStore has rate limits - the default 60-second refresh avoids throttling. Test in Studio by adding fake entries to the OrderedDataStore and confirming they appear in the correct order.
Add it to your game in 3 steps
- 1
Copy the Luau
Open the template in the web editor and click Export. Choose LocalScript to copy the full client Luau to your clipboard.
- 2
Paste into StarterGui
In Roblox Studio, right-click StarterGui in the Explorer, insert a LocalScript, and paste the copied Luau. Rename it to match the template.
- 3
Press Play to verify
Click Play in Studio. The GUI should appear exactly as designed. Tweak any Size or Position values in the script if you want to adjust the layout.
1--[[2 Global Leaderboard - Client Side3 A top-10 global leaderboard with OrderedDataStore integration4 Features: Auto-refresh, smooth animations, avatar display, clean UI5]]67-- Services8local Players = game:GetService("Players")9local TweenService = game:GetService("TweenService")10local ReplicatedStorage = game:GetService("ReplicatedStorage")11local RunService = game:GetService("RunService")12local HttpService = game:GetService("HttpService")1314local player = Players.LocalPlayer15local playerGui = player:WaitForChild("PlayerGui")1617-- Constants18local LEADERBOARD_SIZE = UDim2.new(0, 520, 0, 600)19local LEADERBOARD_POSITION = UDim2.new(0.5, -260, 0.5, -300)20local HEADER_HEIGHT = 7021local ROW_HEIGHT = 5622local FOOTER_HEIGHT = 3623local REFRESH_INTERVAL = 60 -- seconds24local TWEEN_DURATION = 0.3525local STAGGER_DELAY = 0.052627-- Colors28local COLOR_BG = Color3.fromRGB(30, 30, 40)29local COLOR_HEADER = Color3.fromRGB(40, 45, 60)30local COLOR_ACCENT = Color3.fromRGB(255, 200, 50)31local COLOR_TEXT_PRIMARY = Color3.fromRGB(255, 255, 255)32local COLOR_TEXT_SECONDARY = Color3.fromRGB(180, 180, 190)33local COLOR_RANK_GOLD = Color3.fromRGB(255, 215, 0)34local COLOR_RANK_SILVER = Color3.fromRGB(192, 192, 192)35local COLOR_RANK_BRONZE = Color3.fromRGB(205, 127, 50)36local COLOR_ROW_EVEN = Color3.fromRGB(35, 38, 50)37local COLOR_ROW_ODD = Color3.fromRGB(42, 45, 58)38local COLOR_HIGHLIGHT = Color3.fromRGB(255, 200, 50)39local COLOR_BUTTON_HOVER = Color3.fromRGB(60, 65, 85)40local COLOR_CLOSE_RED = Color3.fromRGB(220, 60, 60)4142-- Tween presets43local tweenInfoFade = TweenInfo.new(TWEEN_DURATION, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)44local tweenInfoSlide = TweenInfo.new(TWEEN_DURATION * 1.2, Enum.EasingStyle.Back, Enum.EasingDirection.Out)45local tweenInfoScale = TweenInfo.new(TWEEN_DURATION * 0.8, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out)46local tweenInfoPulse = TweenInfo.new(0.6, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true)4748-- Remote events49local LeaderboardEvents = ReplicatedStorage:WaitForChild("LeaderboardEvents")50local RefreshEvent = LeaderboardEvents:WaitForChild("RefreshLeaderboard")51local GetLeaderboardData = LeaderboardEvents:WaitForChild("GetLeaderboardData")5253-- GUI References (initialized in BuildUI)54local gui, mainFrame, entriesContainer, loadingIndicator, lastUpdatedLabel55local entryTemplate, closeButton, openButton, refreshButton5657-- State58local isVisible = false59local currentEntries = {}60local refreshConnection = nil61local lastRefreshTime = 06263-----------------------------------------------------------64-- Helper Functions65-----------------------------------------------------------6667local function Create(className, props)68 local instance = Instance.new(className)69 for key, value in pairs(props or {}) do70 instance[key] = value71 end72 return instance73end7475local function Tween(instance, properties, tweenInfoOverride)76 local info = tweenInfoOverride or tweenInfoFade77 local tween = TweenService:Create(instance, info, properties)78 tween:Play()79 return tween80end8182local function FormatNumber(num)83 if num >= 1e9 then84 return string.format("%.1fB", num / 1e9)85 elseif num >= 1e6 then86 return string.format("%.1fM", num / 1e6)87 elseif num >= 1e3 then88 return string.format("%.1fK", num / 1e3)89 end90 return tostring(math.floor(num))91end9293local function GetRankColor(rank)94 if rank == 1 then return COLOR_RANK_GOLD end95 if rank == 2 then return COLOR_RANK_SILVER end96 if rank == 3 then return COLOR_RANK_BRONZE end97 return COLOR_TEXT_PRIMARY98end99100local function GetRankSuffix(rank)101 if rank == 1 then return "st" end102 if rank == 2 then return "nd" end103 if rank == 3 then return "rd" end104 return "th"105end106107-----------------------------------------------------------108-- UI Construction109-----------------------------------------------------------110111local function BuildUI()112 -- ScreenGui113 gui = Create("ScreenGui", {114 Name = "LeaderboardGui",115 ResetOnSpawn = false,116 ZIndexBehavior = Enum.ZIndexBehavior.Sibling,117 Enabled = true,118 Parent = playerGui,119 })120121 -- Main Frame122 mainFrame = Create("Frame", {123 Name = "LeaderboardFrame",124 Size = LEADERBOARD_SIZE,125 Position = UDim2.new(0.5, 0, 0.4, 0), -- Start slightly above center for slide-in126 AnchorPoint = Vector2.new(0.5, 0.5),127 BackgroundColor3 = COLOR_BG,128 BorderSizePixel = 0,129 Visible = false,130 ZIndex = 10,131 Parent = gui,132 })133134 Create("UICorner", {135 CornerRadius = UDim.new(0, 12),136 Parent = mainFrame,137 })138139 Create("UIGradient", {140 Color = ColorSequence.new({141 ColorSequenceKeypoint.new(0, Color3.fromRGB(35, 35, 50)),142 ColorSequenceKeypoint.new(1, Color3.fromRGB(25, 25, 35)),143 }),144 Rotation = 90,145 Parent = mainFrame,146 })147148 -- Shadow effect (behind main frame)149 local shadow = Create("ImageLabel", {150 Name = "Shadow",151 Size = UDim2.new(1, 40, 1, 40),152 Position = UDim2.new(0, -20, 0, -20),153 BackgroundTransparency = 1,154 Image = "rbxassetid://5554236805",155 ImageColor3 = Color3.fromRGB(0, 0, 0),156 ImageTransparency = 0.6,157 ScaleType = Enum.ScaleType.Slice,158 SliceCenter = Rect.new(23, 23, 277, 277),159 ZIndex = 9,160 Parent = mainFrame,161 })162163 -- Header Frame164 local headerFrame = Create("Frame", {165 Name = "HeaderFrame",166 Size = UDim2.new(1, 0, 0, HEADER_HEIGHT),167 BackgroundColor3 = COLOR_HEADER,168 BorderSizePixel = 0,169 ZIndex = 11,170 Parent = mainFrame,171 })172173 Create("UICorner", {174 CornerRadius = UDim.new(0, 12),175 Parent = headerFrame,176 })177178 -- Fix header bottom corners179 local headerFix = Create("Frame", {180 Name = "HeaderFix",181 Size = UDim2.new(1, 0, 0, 12),182 Position = UDim2.new(0, 0, 1, -12),183 BackgroundColor3 = COLOR_HEADER,184 BorderSizePixel = 0,185 ZIndex = 11,186 Parent = headerFrame,187 })188189 -- Title190 local titleLabel = Create("TextLabel", {191 Name = "TitleLabel",192 Size = UDim2.new(0.6, 0, 0, 36),193 Position = UDim2.new(0, 20, 0, 8),194 BackgroundTransparency = 1,195 Text = "🏆 Global Leaderboard",196 TextColor3 = COLOR_TEXT_PRIMARY,197 TextSize = 24,198 Font = Enum.Font.GothamBold,199 TextXAlignment = Enum.TextXAlignment.Left,200 ZIndex = 12,201 Parent = headerFrame,202 })203204 -- Subtitle205 Create("TextLabel", {206 Name = "SubtitleLabel",207 Size = UDim2.new(0.6, 0, 0, 20),208 Position = UDim2.new(0, 20, 0, 42),209 BackgroundTransparency = 1,210 Text = "Top 10 Players Worldwide",211 TextColor3 = COLOR_TEXT_SECONDARY,212 TextSize = 13,213 Font = Enum.Font.Gotham,214 TextXAlignment = Enum.TextXAlignment.Left,215 ZIndex = 12,216 Parent = headerFrame,217 })218219 -- Refresh Button220 refreshButton = Create("TextButton", {221 Name = "RefreshButton",222 Size = UDim2.new(0, 80, 0, 32),223 Position = UDim2.new(1, -100, 0, 19),224 AnchorPoint = Vector2.new(0, 0),225 BackgroundColor3 = COLOR_BUTTON_HOVER,226 Text = "🔄 Refresh",227 TextColor3 = COLOR_TEXT_PRIMARY,228 TextSize = 12,229 Font = Enum.Font.GothamSemibold,230 AutoButtonColor = false,231 ZIndex = 12,232 Parent = headerFrame,233 })234235 Create("UICorner", {236 CornerRadius = UDim.new(0, 8),237 Parent = refreshButton,238 })239240 -- Divider241 Create("Frame", {242 Name = "Divider",243 Size = UDim2.new(1, -20, 0, 1),244 Position = UDim2.new(0, 10, 0, HEADER_HEIGHT),245 BackgroundColor3 = Color3.fromRGB(60, 60, 75),246 BorderSizePixel = 0,247 ZIndex = 11,248 Parent = mainFrame,249 })250251 -- Column Headers252 local columnHeaders = Create("Frame", {253 Name = "ColumnHeaders",254 Size = UDim2.new(1, -20, 0, 28),255 Position = UDim2.new(0, 10, 0, HEADER_HEIGHT + 6),256 BackgroundTransparency = 1,257 ZIndex = 11,258 Parent = mainFrame,259 })260261 Create("TextLabel", {262 Name = "RankHeader",263 Size = UDim2.new(0, 60, 1, 0),264 Position = UDim2.new(0, 10, 0, 0),265 BackgroundTransparency = 1,266 Text = "RANK",267 TextColor3 = COLOR_ACCENT,268 TextSize = 12,269 Font = Enum.Font.GothamBold,270 TextXAlignment = Enum.TextXAlignment.Center,271 ZIndex = 12,272 Parent = columnHeaders,273 })274275 Create("TextLabel", {276 Name = "PlayerHeader",277 Size = UDim2.new(0, 200, 1, 0),278 Position = UDim2.new(0, 80, 0, 0),279 BackgroundTransparency = 1,280 Text = "PLAYER",281 TextColor3 = COLOR_ACCENT,282 TextSize = 12,283 Font = Enum.Font.GothamBold,284 TextXAlignment = Enum.TextXAlignment.Left,285 ZIndex = 12,286 Parent = columnHeaders,287 })288289 Create("TextLabel", {290 Name = "ScoreHeader",291 Size = UDim2.new(0, 120, 1, 0),292 Position = UDim2.new(1, -130, 0, 0),293 BackgroundTransparency = 1,294 Text = "SCORE",295 TextColor3 = COLOR_ACCENT,296 TextSize = 12,297 Font = Enum.Font.GothamBold,298 TextXAlignment = Enum.TextXAlignment.Right,299 ZIndex = 12,300 Parent = columnHeaders,301 })302303 -- Entries Container (ScrollingFrame)304 entriesContainer = Create("ScrollingFrame", {305 Name = "EntriesContainer",306 Size = UDim2.new(1, -20, 1, -(HEADER_HEIGHT + FOOTER_HEIGHT + 50)),307 Position = UDim2.new(0, 10, 0, HEADER_HEIGHT + 38),308 BackgroundTransparency = 1,309 BorderSizePixel = 0,310 ScrollBarThickness = 4,311 ScrollBarImageColor3 = COLOR_ACCENT,312 ScrollBarImageTransparency = 0.5,313 CanvasSize = UDim2.new(0, 0, 0, 0),314 ZIndex = 11,315 Parent = mainFrame,316 })317318 Create("UIListLayout", {319 Padding = UDim.new(0, 4),320 SortOrder = Enum.SortOrder.LayoutOrder,321 Parent = entriesContainer,322 })323324 -- Entry Template (hidden, cloned for each entry)325 entryTemplate = Create("Frame", {326 Name = "EntryTemplate",327 Size = UDim2.new(1, 0, 0, ROW_HEIGHT),328 BackgroundColor3 = COLOR_ROW_ODD,329 BorderSizePixel = 0,330 Visible = false,331 ZIndex = 11,332 })333334 Create("UICorner", {335 CornerRadius = UDim.new(0, 8),336 Parent = entryTemplate,337 })338339 -- Rank background circle340 local rankBg = Create("Frame", {341 Name = "RankBg",342 Size = UDim2.new(0, 36, 0, 36),343 Position = UDim2.new(0, 12, 0.5, 0),344 AnchorPoint = Vector2.new(0, 0.5),345 BackgroundColor3 = COLOR_HEADER,346 BorderSizePixel = 0,347 ZIndex = 12,348 Parent = entryTemplate,349 })350351 Create("UICorner", {352 CornerRadius = UDim.new(1, 0),353 Parent = rankBg,354 })355356 Create("TextLabel", {357 Name = "RankLabel",358 Size = UDim2.new(1, 0, 1, 0),359 BackgroundTransparency = 1,360 Text = "1",361 TextColor3 = COLOR_RANK_GOLD,362 TextSize = 16,363 Font = Enum.Font.GothamBold,364 TextXAlignment = Enum.TextXAlignment.Center,365 TextYAlignment = Enum.TextYAlignment.Center,366 ZIndex = 13,367 Parent = rankBg,368 })369370 -- Avatar371 local avatarFrame = Create("Frame", {372 Name = "AvatarFrame",373 Size = UDim2.new(0, 40, 0, 40),374 Position = UDim2.new(0, 58, 0.5, 0),375 AnchorPoint = Vector2.new(0, 0.5),376 BackgroundColor3 = COLOR_HEADER,377 BorderSizePixel = 0,378 ZIndex = 12,379 Parent = entryTemplate,380 })381382 Create("UICorner", {383 CornerRadius = UDim.new(1, 0),384 Parent = avatarFrame,385 })386387 Create("ImageLabel", {388 Name = "AvatarImage",389 Size = UDim2.new(1, -4, 1, -4),390 Position = UDim2.new(0, 2, 0, 2),391 BackgroundTransparency = 1,392 Image = "",393 ZIndex = 13,394 Parent = avatarFrame,395 })396397 -- Player Name398 Create("TextLabel", {399 Name = "PlayerNameLabel",400 Size = UDim2.new(0, 180, 0, ROW_HEIGHT),401 Position = UDim2.new(0, 108, 0, 0),402 BackgroundTransparency = 1,403 Text = "PlayerName",404 TextColor3 = COLOR_TEXT_PRIMARY,405 TextSize = 15,406 Font = Enum.Font.GothamSemibold,407 TextXAlignment = Enum.TextXAlignment.Left,408 TextTruncate = Enum.TextTruncate.AtEnd,409 ZIndex = 12,410 Parent = entryTemplate,411 })412413 -- Score414 Create("TextLabel", {415 Name = "ScoreLabel",416 Size = UDim2.new(0, 120, 0, ROW_HEIGHT),417 Position = UDim2.new(1, -130, 0, 0),418 BackgroundTransparency = 1,419 Text = "0",420 TextColor3 = COLOR_ACCENT,421 TextSize = 16,422 Font = Enum.Font.GothamBold,423 TextXAlignment = Enum.TextXAlignment.Right,424 ZIndex = 12,425 Parent = entryTemplate,426 })427428 -- Loading Indicator429 loadingIndicator = Create("Frame", {430 Name = "LoadingIndicator",431 Size = UDim2.new(1, 0, 0, 100),432 Position = UDim2.new(0, 0, 0, HEADER_HEIGHT + 40),433 BackgroundTransparency = 1,434 Visible = false,435 ZIndex = 15,436 Parent = mainFrame,437 })438439 Create("TextLabel", {440 Name = "LoadingText",441 Size = UDim2.new(1, 0, 1, 0),442 BackgroundTransparency = 1,443 Text = "⏳ Loading leaderboard data...",444 TextColor3 = COLOR_TEXT_SECONDARY,445 TextSize = 16,446 Font = Enum.Font.Gotham,447 TextXAlignment = Enum.TextXAlignment.Center,448 TextYAlignment = Enum.TextYAlignment.Center,449 ZIndex = 16,450 Parent = loadingIndicator,451 })452453 -- Footer Frame454 local footerFrame = Create("Frame", {455 Name = "FooterFrame",456 Size = UDim2.new(1, 0, 0, FOOTER_HEIGHT),457 Position = UDim2.new(0, 0, 1, -FOOTER_HEIGHT),458 BackgroundColor3 = COLOR_HEADER,459 BorderSizePixel = 0,460 ZIndex = 11,461 Parent = mainFrame,462 })463464 Create("UICorner", {465 CornerRadius = UDim.new(0, 12),466 Parent = footerFrame,467 })468469 local footerFix = Create("Frame", {470 Name = "FooterFix",471 Size = UDim2.new(1, 0, 0, 12),472 Position = UDim2.new(0, 0, 0, 0),473 BackgroundColor3 = COLOR_HEADER,474 BorderSizePixel = 0,475 ZIndex = 11,476 Parent = footerFrame,477 })478479 lastUpdatedLabel = Create("TextLabel", {480 Name = "LastUpdatedLabel",481 Size = UDim2.new(0.7, 0, 1, 0),482 Position = UDim2.new(0, 20, 0, 0),483 BackgroundTransparency = 1,484 Text = "Last updated: Never",485 TextColor3 = COLOR_TEXT_SECONDARY,486 TextSize = 11,487 Font = Enum.Font.Gotham,488 TextXAlignment = Enum.TextXAlignment.Left,489 ZIndex = 12,490 Parent = footerFrame,491 })492493 -- Close Button494 closeButton = Create("TextButton", {495 Name = "CloseButton",496 Size = UDim2.new(0, 70, 0, 26),497 Position = UDim2.new(1, -90, 0, 5),498 BackgroundColor3 = COLOR_CLOSE_RED,499 Text = "✕ Close",500 TextColor3 = COLOR_TEXT_PRIMARY,501 TextSize = 12,502 Font = Enum.Font.GothamSemibold,503 AutoButtonColor = false,504 ZIndex = 12,505 Parent = footerFrame,506 })507508 Create("UICorner", {509 CornerRadius = UDim.new(0, 6),510 Parent = closeButton,511 })512513 -- Open Button (when leaderboard is closed)514 openButton = Create("TextButton", {515 Name = "OpenButton",516 Size = UDim2.new(0, 160, 0, 44),517 Position = UDim2.new(0, 20, 0.5, -22),518 BackgroundColor3 = COLOR_HEADER,519 Text = "🏆 Leaderboard",520 TextColor3 = COLOR_ACCENT,521 TextSize = 16,522 Font = Enum.Font.GothamBold,523 AutoButtonColor = false,524 Visible = true,525 ZIndex = 5,526 Parent = gui,527 })528529 Create("UICorner", {530 CornerRadius = UDim.new(0, 10),531 Parent = openButton,532 })533534 -- Open button shadow535 Create("ImageLabel", {536 Name = "OpenShadow",537 Size = UDim2.new(1, 20, 1, 20),538 Position = UDim2.new(0, -10, 0, -10),539 BackgroundTransparency = 1,540 Image = "rbxassetid://5554236805",541 ImageColor3 = Color3.fromRGB(0, 0, 0),542 ImageTransparency = 0.7,543 ScaleType = Enum.ScaleType.Slice,544 SliceCenter = Rect.new(23, 23, 277, 277),545 ZIndex = 4,546 Parent = openButton,547 })548end549550-----------------------------------------------------------551-- Entry Management552-----------------------------------------------------------553554local function ClearEntries()555 for _, entry in ipairs(currentEntries) do556 Tween(entry, {BackgroundTransparency = 1})557 task.delay(TWEEN_DURATION, function()558 if entry and entry.Parent then559 entry:Destroy()560 end561 end)562 end563 currentEntries = {}564end565566local function CreateEntry(rank, playerName, score, userId, isLocalPlayer)567 local entry = entryTemplate:Clone()568 entry.Name = "Entry_" .. rank569 entry.Visible = true570 entry.LayoutOrder = rank571 entry.BackgroundTransparency = 0572573 -- Alternate row colors574 if rank % 2 == 0 then575 entry.BackgroundColor3 = COLOR_ROW_EVEN576 else577 entry.BackgroundColor3 = COLOR_ROW_ODD578 end579580 -- Highlight local player581 if isLocalPlayer then582 entry.BackgroundColor3 = Color3.fromRGB(55, 50, 35)583 local stroke = Instance.new("UIStroke")584 stroke.Color = COLOR_HIGHLIGHT585 stroke.Thickness = 2586 stroke.Transparency = 0.3587 stroke.Parent = entry588 end589590 -- Rank591 local rankBg = entry:FindFirstChild("RankBg")592 if rankBg then593 local rankLabel = rankBg:FindFirstChild("RankLabel")594 if rankLabel then595 rankLabel.Text = tostring(rank) .. GetRankSuffix(rank)596 rankLabel.TextColor3 = GetRankColor(rank)597 end598 end599600 -- Avatar601 local avatarImage = entry:FindFirstChild("AvatarFrame")602 if avatarImage then603 local imgLabel = avatarImage:FindFirstChild("AvatarImage")604 if imgLabel and userId then605 imgLabel.Image = "rbxthumb://type=AvatarHeadShot&id=" .. userId .. "&w=48&h=48"606 else607 imgLabel.Image = "rbxassetid://0"608 end609 end610611 -- Player Name612 local nameLabel = entry:FindFirstChild("PlayerNameLabel")613 if nameLabel then614 nameLabel.Text = playerName615 if isLocalPlayer then616 nameLabel.Text = playerName .. " (YOU)"617 nameLabel.TextColor3 = COLOR_HIGHLIGHT618 end619 end620621 -- Score622 local scoreLabel = entry:FindFirstChild("ScoreLabel")623 if scoreLabel then624 scoreLabel.Text = FormatNumber(score)625 end626627 entry.Parent = entriesContainer628 table.insert(currentEntries, entry)629630 -- Animate entry in631 entry.Size = UDim2.new(0.9, 0, 0, ROW_HEIGHT)632 entry.BackgroundTransparency = 1633634 task.delay((rank - 1) * STAGGER_DELAY, function()635 if entry and entry.Parent then636 Tween(entry, {637 Size = UDim2.new(1, 0, 0, ROW_HEIGHT),638 BackgroundTransparency = 0,639 }, tweenInfoSlide)640 end641 end)642end643644-----------------------------------------------------------645-- Data Loading646-----------------------------------------------------------647648local function UpdateLeaderboard(data)649 -- Clear existing entries650 ClearEntries()651652 -- Hide loading653 loadingIndicator.Visible = false654655 if not data or #data == 0 then656 -- Show "no data" message657 local noDataLabel = Create("TextLabel", {658 Name = "NoDataLabel",659 Size = UDim2.new(1, 0, 0, 100),660 BackgroundTransparency = 1,661 Text = "📭 No data yet. Be the first to set a score!",662 TextColor3 = COLOR_TEXT_SECONDARY,663 TextSize = 15,664 Font = Enum.Font.Gotham,665 TextXAlignment = Enum.TextXAlignment.Center,666 TextYAlignment = Enum.TextYAlignment.Center,667 ZIndex = 14,668 Parent = entriesContainer,669 })670 table.insert(currentEntries, noDataLabel)671 entriesContainer.CanvasSize = UDim2.new(0, 0, 0, 120)672 return673 end674675 -- Create entries676 for i, entryData in ipairs(data) do677 if i > 10 then break end678 local isLocalPlayer = entryData.UserId == player.UserId679 CreateEntry(680 i,681 entryData.DisplayName or entryData.Name or "Unknown",682 entryData.Score or 0,683 entryData.UserId,684 isLocalPlayer685 )686 end687688 -- Update canvas size689 local contentHeight = math.min(#data, 10) * (ROW_HEIGHT + 4)690 entriesContainer.CanvasSize = UDim2.new(0, 0, 0, contentHeight)691692 -- Update timestamp693 lastRefreshTime = os.time()694 lastUpdatedLabel.Text = "Last updated: " .. os.date("%H:%M:%S", lastRefreshTime)695end696697local function RefreshLeaderboard()698 -- Prevent spam refreshing699 local timeSinceLastRefresh = os.time() - lastRefreshTime700 if timeSinceLastRefresh < 5 then701 return702 end703704 -- Show loading705 loadingIndicator.Visible = true706707 -- Request data from server708 local success, data = pcall(function()709 return GetLeaderboardData:InvokeServer()710 end)711712 if success and data then713 UpdateLeaderboard(data)714 else715 loadingIndicator.Visible = false716 warn("[Leaderboard] Failed to refresh: " .. tostring(data))717718 -- Show error message719 ClearEntries()720 local errorLabel = Create("TextLabel", {721 Name = "ErrorLabel",722 Size = UDim2.new(1, 0, 0, 100),723 BackgroundTransparency = 1,724 Text = "❌ Failed to load data. Try again.",725 TextColor3 = Color3.fromRGB(255, 100, 100),726 TextSize = 15,727 Font = Enum.Font.Gotham,728 TextXAlignment = Enum.TextXAlignment.Center,729 TextYAlignment = Enum.TextYAlignment.Center,730 ZIndex = 14,731 Parent = entriesContainer,732 })733 table.insert(currentEntries, errorLabel)734 end735end736737-----------------------------------------------------------738-- Visibility Toggle739-----------------------------------------------------------740741local function ShowLeaderboard()742 if isVisible then return end743 isVisible = true744745 mainFrame.Visible = true746 openButton.Visible = false747748 -- Slide in animation749 mainFrame.Position = UDim2.new(0.5, 0, 0.35, 0)750 mainFrame.BackgroundTransparency = 1751752 Tween(mainFrame, {753 Position = LEADERBOARD_POSITION,754 BackgroundTransparency = 0,755 }, tweenInfoSlide)756757 -- Fade in shadow758 local shadow = mainFrame:FindFirstChild("Shadow")759 if shadow then760 shadow.ImageTransparency = 1761 Tween(shadow, {ImageTransparency = 0.6}, tweenInfoFade)762 end763764 -- Refresh data on open765 RefreshLeaderboard()766end767768local function HideLeaderboard()769 if not isVisible then return end770 isVisible = false771772 -- Fade out animation773 Tween(mainFrame, {774 Position = UDim2.new(0.5, 0, 0.35, 0),775 BackgroundTransparency = 1,776 }, tweenInfoFade)777778 -- Fade out shadow779 local shadow = mainFrame:FindFirstChild("Shadow")780 if shadow then781 Tween(shadow, {ImageTransparency = 1}, tweenInfoFade)782 end783784 task.delay(TWEEN_DURATION, function()785 mainFrame.Visible = false786 openButton.Visible = true787788 -- Pop in animation for open button789 openButton.Size = UDim2.new(0, 0, 0, 0)790 Tween(openButton, {791 Size = UDim2.new(0, 160, 0, 44),792 }, tweenInfoScale)793 end)794end795796-----------------------------------------------------------797-- Button Interactions798-----------------------------------------------------------799800local function SetupButtonAnimations()801 -- Refresh button hover802 refreshButton.MouseEnter:Connect(function()803 Tween(refreshButton, {BackgroundColor3 = COLOR_ACCENT})804 refreshButton.TextColor3 = COLOR_BG805 end)806807 refreshButton.MouseLeave:Connect(function()808 Tween(refreshButton, {BackgroundColor3 = COLOR_BUTTON_HOVER})809 refreshButton.TextColor3 = COLOR_TEXT_PRIMARY810 end)811812 refreshButton.MouseButton1Click:Connect(function()813 -- Spin animation814 local originalRotation = refreshButton.Rotation815 Tween(refreshButton, {Rotation = 360}, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out))816 task.delay(0.5, function()817 refreshButton.Rotation = 0818 end)819 RefreshLeaderboard()820 end)821822 -- Close button hover823 closeButton.MouseEnter:Connect(function()824 Tween(closeButton, {BackgroundColor3 = Color3.fromRGB(255, 80, 80)})825 end)826827 closeButton.MouseLeave:Connect(function()828 Tween(closeButton, {BackgroundColor3 = COLOR_CLOSE_RED})829 end)830831 closeButton.MouseButton1Click:Connect(HideLeaderboard)832833 -- Open button hover834 openButton.MouseEnter:Connect(function()835 Tween(openButton, {BackgroundColor3 = Color3.fromRGB(60, 65, 90)})836 Tween(openButton, {Size = UDim2.new(0, 170, 0, 48)})837 end)838839 openButton.MouseLeave:Connect(function()840 Tween(openButton, {BackgroundColor3 = COLOR_HEADER})841 Tween(openButton, {Size = UDim2.new(0, 160, 0, 44)})842 end)843844 openButton.MouseButton1Click:Connect(ShowLeaderboard)845end846847-----------------------------------------------------------848-- Auto Refresh849-----------------------------------------------------------850851local function StartAutoRefresh()852 if refreshConnection then853 refreshConnection:Disconnect()854 end855856 refreshConnection = task.spawn(function()857 while true do858 task.wait(REFRESH_INTERVAL)859 if isVisible then860 RefreshLeaderboard()861 end862 end863 end)864end865866-----------------------------------------------------------867-- Keyboard Shortcut868-----------------------------------------------------------869870local function SetupKeyboardShortcut()871 local UserInputService = game:GetService("UserInputService")872873 UserInputService.InputBegan:Connect(function(input, gameProcessed)874 if gameProcessed then return end875 if input.KeyCode == Enum.KeyCode.L then876 if isVisible then877 HideLeaderboard()878 else879 ShowLeaderboard()880 end881 end882 end)883end884885-----------------------------------------------------------886-- Initialization887-----------------------------------------------------------888889local function Initialize()890 BuildUI()891 SetupButtonAnimations()892 StartAutoRefresh()893 SetupKeyboardShortcut()894895 -- Listen for server-pushed updates896 RefreshEvent.OnClientEvent:Connect(function(data)897 if isVisible then898 UpdateLeaderboard(data)899 end900 end)901902 print("[Leaderboard] Global Leaderboard initialized. Press 'L' to toggle.")903end904905-- Wait for player to be ready906if player.Character then907 Initialize()908else909 player.CharacterAdded:Wait()910 Initialize()911end