I’m making a global leaderboard GUI using cloning of a template I created and only sometimes they are showing up, although they are supposed to be visible.
(When it does show up, it’s only showing the first place)
The script (in ServerScriptService):
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetOrderedDataStore("Data")
local function updateLeaderboard()
local success, err = pcall(function()
local Data = DataStore:GetSortedAsync(false, 5)
local KillsPage = Data:GetCurrentPage()
for Rank, data in ipairs(KillsPage) do
local username = "Failed to load name"
local success, err = pcall(function()
username = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
end)
print(username)
local Name = username
local Kills = data.value
local isOnLeaderboard = false
for i, v in pairs(game.StarterGui.MainMenuGui.Leaderstats.Holder.ScrollingFrame:GetChildren()) do
if v.Username.Text == Name then
isOnLeaderboard = true
break
end
end
if Kills and isOnLeaderboard == false then
local newFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
newFrame.Username.Text = Name
newFrame.Kills.Text = Kills
newFrame.Rank.Text = Rank
newFrame.Position = UDim2.new(0, 0, newFrame.Position.Y.Scale + (0.048 * #game.StarterGui.MainMenuGui.Leaderstats.Holder.ScrollingFrame:GetChildren()), 0)
newFrame.Parent = game.StarterGui.MainMenuGui.Leaderstats.Holder.ScrollingFrame
end
end
end)
if not success then
warn(err)
end
end
while true do
for _, player in pairs(game.Players:GetPlayers()) do
DataStore:SetAsync(player.UserId, player.stats.Kills.Value)
end
for _, frame in pairs(game.StarterGui.MainMenuGui.Leaderstats.Holder.ScrollingFrame:GetChildren()) do
frame:Destroy()
end
updateLeaderboard()
print("Leaderboard Updated")
wait(math.random(40, 60))
end
Test 1:
Test 2: