My friend and I are trying to make a leaderboard. For some reason, nothing in the for loop works. Does anyone have ideas?
local DataStoreService = game:GetService("DataStoreService")
local DS2 = game.ServerScriptService.DataStore2
local LevelDataStore = DataStoreService:GetOrderedDataStore("LevelDataStore")
local LeaderboardPart = script.Parent.Parent.Parent
local RefreshRate = 5
function RefreshLeaderboard()
for i, plr in pairs(game.Players:GetPlayers()) do
LevelDataStore:SetAsync(plr.UserId, plr.leaderstats:WaitForChild("Level").Value)
end
local success, errormsg = pcall(function()
local Data = LevelDataStore:GetSortedAsync(false, 10)
local LevelPage = Data:GetCurrentPage()
for i, v in ipairs(LevelPage) do
print(v)
local UserName = game.Players:GetNameFromUserIdAsync(tonumber(v.key))
print(game.Players:GetNameFromUserIdAsync(tonumber(v.key)))
local Level = v.value
if Level then
print("Level Is True")
local NewSample = script.Parent.Template:Clone()
NewSample.Parent = LeaderboardPart.SurfaceGui.ScrollingFrame
NewSample.Name = UserName
NewSample.Rank.Text = "# " .. i
NewSample.PlrName.Text = UserName
NewSample.Level.Text = Level
end
end
end)
end
while wait(1) do
print("While wait here")
for i, v in pairs(LeaderboardPart.SurfaceGui.ScrollingFrame:GetChildren()) do
if v.Name ~= "Template" and v:IsA("Frame") then
v:Destroy()
end
end
RefreshLeaderboard()
wait(RefreshRate)
end