RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"Make me a leaderboard scripts where players can see others stats like coins and rebirths"
-- leaderboard script (ServerScriptService) local Players = game:GetService("Players") local function onPlayerAdded(player) local stats = Instance.new("Folder") stats.Name = "leaderstats" stats.Parent = player local coins = Instance.new("IntValue") coins.Name = "Coins" coins.Value = 0 coins.Parent = stats local rebirths = Instance.new("IntValue") rebirths.Name = "Rebirths" rebirths.Value = 0 rebirths.Parent = stats end Players.PlayerAdded:Connect(onPlayerAdded) for _, player in ipairs(Players:GetPlayers()) do onPlayerAdded(player) end -- leaderboard GUI script (LocalScript in StarterGui) local Players = game:GetService("Players") local leaderboardGUI = script.Parent.LeaderboardGUI local playerList = leaderboardGUI.PlayerList local function updateLeaderboard() playerList:ClearAllChildren() local playersStats = {} for _, player in ipairs(Players:GetPlayers()) do local stats = player:FindFirstChild("leaderstats") if stats then table.insert(playersStats, { Name = player.Name, Coins = stats.Coins.Value, Rebirths = stats.Rebirths.Value }) end end table.sort(playersStats, function(a, b) return a.Coins > b.Coins end) for _, playerStats in ipairs(playersStats) do local entry = Instance.new("TextLabel") entry.Size = UDim2.new(1, 0, 0, 30) entry.BackgroundTransparency = 1 entry.Font = Enum.Font.SourceSans entry.TextSize = 18 entry.TextColor3 = Color3.new(1, 1, 1) entry.Text = string.format("%s - Coins: %d - Rebirths: %d", playerStats.Name, playerStats.Coins, playerStats.Rebirths) entry.Parent = playerList end end Players.PlayerAdded:Connect(updateLeaderboard) Players.PlayerRemoving:Connect(updateLeaderboard) updateLeaderboard() while true do wait(5) updateLeaderboard() end