Hello, I’m trying to create a leaderboard but the leaderboard script stops going further than line 45 where I get the name of the player so I can create a template frame for the leaderboard. I have no clue why it happens. One of my other leaderboards that runs over the exact same script works fine but this one just stops running.Hope u guys can give some feedback that might can help me. Here is the script:
local ds = game:GetService("DataStoreService")
local coinsODS = ds:GetOrderedDataStore("eS")
local tfm = require(game.ReplicatedStorage:WaitForChild("TFM"))
local timeUntilReset = 30
local Short = require(game.ReplicatedStorage:WaitForChild("Short"))
while wait(1) do
timeUntilReset = timeUntilReset - 1
if timeUntilReset == 0 then
timeUntilReset = 30
for i, plr in pairs(game.Players:GetPlayers()) do
coinsODS:SetAsync(plr.UserId, plr.Stats.TimePlayed.Value)
end
for i, leaderboardRank in pairs(script.Parent:GetChildren()) do
if leaderboardRank.ClassName == "Frame" then
leaderboardRank:Destroy()
end
end
local success, errorMsg = pcall(function()
local data = coinsODS:GetSortedAsync(false, 100)
local coinsPage = data:GetCurrentPage()
for rankInLB, dataStored in ipairs(coinsPage) do
local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
local userid = game.Players:GetUserIdFromNameAsync(name)
local coins = dataStored.value
local template = script.Template:Clone()
template.Name = name .. "Leaderboard"
template.PlrName.Text = name
template.Rank.Text = "#" .. rankInLB
template.Coins.Text = tfm:Convert(coins, "Short", false)
template.Parent = script.Parent
if rankInLB == 1 then
game.Workspace.NpcTimePlayed.UserId.Value = userid
end
end
end)
end
end