Hello there,
I was working on making a script for a basic leaderboard. The issue that i am having is when I collect a snowball, it should add me on the leaderboard since I would have the most out of the whole game. However, this is not what the outcome currently is. I am not added to the leaderboard, and no errors are outputted. Let me know if you have any suggestions!
local dss = game:GetService("DataStoreService")
local ds = dss:GetOrderedDataStore("MostSnowballs")
local frame = script.Parent.ScrollingFrame
local template = frame.Template
local function updateLeaderboard()
local success,errorMessage = pcall(function()
local data = ds:GetSortedAsync(false,5)
local snowballsPage = data:GetCurrentPage()
for rank,value in ipairs(snowballsPage) do
local username = game.Players:GetNameFromUserIdAsync(tonumber(value.Key))
local snowballs = value.value
local isOnBoard = false
for a,b in pairs(frame:GetChildren()) do
if b:IsA("TextLabel") then
if b.Text:split(" ")[2] == username and v.Name ~= "Template" then
isOnBoard = true
end
end
end
if snowballs and isOnBoard == false then
local newEntry = template:Clone()
newEntry.Name = username
newEntry.Parent = frame
newEntry.Text = "<b>#".. rank ..": ".. username .." - ".. snowballs .." Snowballs"
newEntry.Visible = true
end
end
end)
end
local function clearBoard()
for i,v in pairs(frame:GetChildren()) do
if v:IsA("TextLabel") then
if v.Name ~= "Template" and v.Name ~= "Title" then
v:Destroy()
end
end
end
end
while wait(30) do
for i,v in pairs(game.Players:GetPlayers()) do
if v.leaderstats.Snowballs.Value >= 1 then
ds:SetAsync(v.UserId,v.leaderstats.Snowballs.Value)
end
end
clearBoard()
updateLeaderboard()
end
Thank you!