So i’m trying to make a Global Donation leaderboard work. Everything works apart from one for loop where it updates the players data to the ordered datastore. It will update it when the player leaves the game but not in the while loop that updates the leaderboard. No errors in the output. Can anyone tell me what’s wrong. Problem is at bottom while loop of script
local StarterGui = game:GetService("StarterGui")
local DataStoreService = game:GetService("DataStoreService")
local DonationLeaderboard = DataStoreService:GetOrderedDataStore("Donationleaderboard")
local Players = game:GetService("Players")
local products = {
{
["Id"] = 1705593449,
["Price"] = 10
},
{
["Id"] = 1705594693,
["Price"] = 100
},
{
["Id"] = 1705595838,
["Price"] = 100000
},
{
["Id"] = 1705595734,
["Price"] = 10000
},
{
["Id"] = 1705595371,
["Price"] = 1000
},
{
["Id"] = 1705593593,
["Price"] = 25
},
{
["Id"] = 1705594960,
["Price"] = 250
},
{
["Id"] = 1705594418,
["Price"] = 50
},
{
["Id"] = 1705595079,
["Price"] = 500
},
{
["Id"] = 1705595660,
["Price"] = 5000
},
{
["Id"] = 1705594530,
["Price"] = 75
},
{
["Id"] = 1705595241,
["Price"] = 750
}
}
local leaderboard = game.StarterGui.GlobalDonationLeaderboard
local function leaderboardSetUp()
for i, product in pairs(products) do
local newButton = leaderboard.Donate.Template:Clone()
newButton.Visible = true
newButton.Id.Value = product.Id
newButton.Text = tostring(product.Price).." Robux"
newButton.Parent = leaderboard.Donate
newButton.Name = tostring(product.Price)
newButton.LayoutOrder = product.Price
end
end
local function updateLeaderBoard()
local success, errormessage = pcall(function()
local Data = DonationLeaderboard:GetSortedAsync(false, 50, 1)
local Page = Data:GetCurrentPage()
for rank, data in ipairs(Page) do
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local name = userName
local Donated = data.value
local isonLeaderboard = false
if Donated and isonLeaderboard == false then
local newFrame = leaderboard.ScrollingFrame:FindFirstChild("Template"):Clone()
newFrame.UserName.Text = name
newFrame.Robux.Text = Donated
newFrame.Rank.Text = "#"..rank
newFrame.Parent = leaderboard.ScrollingFrame
newFrame.LayoutOrder = rank
newFrame.Visible = true
newFrame.Name = name
end
end
end)
if not success then
print(errormessage)
end
end
Players.PlayerRemoving:Connect(function(player)
DonationLeaderboard:SetAsync(player.UserId, player.Donated.Value)
end)
leaderboardSetUp()
while true do
for i, player in pairs(Players:GetPlayers()) do
DonationLeaderboard:SetAsync(player.UserId, player.Donated.Value)
print("Updated "..player.Name)
end
for i, frame in pairs(leaderboard.ScrollingFrame:GetChildren()) do
if frame:IsA("Frame") then
if frame.Name ~= "Template" then
frame:Destroy()
end
end
end
updateLeaderBoard()
task.wait(60)
end