So I am trying to make a activity board which would have the top 4 players with the most activity within the game displayed on a leaderboard but the script that I wrote it doesn’t really work. It prints that it updated and it does not error but the frame itself is not displayed on the surface GUI, even tho it prints that its updating the frame. Here is my code:
-- script name and stuff comes here
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local ActivityData = DataStoreService:GetOrderedDataStore("ActivityStore")
local function UpdateLeaderboard()
local success, errorMsg = pcall(function()
local Data = ActivityData:GetSortedASync(false, 4)
local ActivityPage = Data:GetCurrentPage()
for Rank, data in ipairs(ActivityPage) do
local Username = Players:GetNameFromUserIdAsync(tonumber(data.key))
local PlayerName = Username
local Activity = data.value
local OnLeaderboard = false
for i,v in pairs(workspace.ActivityBoard_Bar.SurfaceGui.ScrollingFrame:GetChildren()) do
if v.Username.Text == PlayerName then
OnLeaderboard = true
break
end
end
if Activity and not OnLeaderboard then
local Sample = game.ReplicatedStorage:WaitForChild("LeaderboardExample"):Clone()
Sample.Username.Text = PlayerName
Sample.MinuteWorked.Text = Activity
Sample.Parent = workspace.ActivityBoard_Bar.SurfaceGui.ScrollingFrame
end
end
end)
if not success then
warn(errorMsg)
end
end
while true do
for _, Player in pairs(Players:GetPlayers()) do
ActivityData:SetAsync(Player.UserId, Player.leaderstats.Activity.Value)
end
for _, frame in pairs(workspace.ActivityBoard_Bar.SurfaceGui.ScrollingFrame:GetChildren()) do
frame:Destroy()
end
UpdateLeaderboard()
print("Updated!")
wait(120)
end