local DataStoreService = game:GetService("DataStoreService")
local PartsDataStore = DataStoreService:GetOrderedDataStore("PartsLeaderboard")
local LeaderboardPart = script.Parent.Parent.Parent
local RefreshRate = 10
local function RefreshLeaderboard()
for i, Player in pairs(game.Players:GetPlayers()) do
PartsDataStore:SetAsync(Player.UserId, Player.leaderstats.Parts.Value)
end
local Success, Error = pcall(function()
local Data = PartsDataStore:GetSortedAsync(false, 10)
local PartsPage = Data:GetCurrentPage()
for Rank, SavedData in ipairs(PartsPage) do
local Username = game.Players:GetNameFromUserIdAsync(tonumber(SavedData.key))
local Parts = SavedData.value
if Parts then
local NewSample = script.Parent.Sample:Clone()
NewSample.Visible = true
NewSample.Parent = LeaderboardPart.SurfaceGui.PlayerHandler
NewSample.Name = Username
NewSample.RankLabel = "#"..Rank
NewSample.NameLabel = Username
NewSample.PartsLabel = Parts
end
end
end)
end
while true do
for i, Frame in pairs(LeaderboardPart.SurfaceGui.PlayerHandler:GetChildren()) do
if Frame.Name ~= "Simple" and Frame:IsA("Frame") then
Frame:Destroy()
end
end
RefreshLeaderboard()
wait(RefreshRate)
end
Okay so you’d need to make it so if a player has joined they’d automatically be added to the leaderboard, right. Then you’d need to make it so it automatically updates the amount of parts they have.