I am creating a leaderboard, although this function for i,v in pairs() is not running.
This is required to stop multiple frames to clone, all displaying the same username. I was looking around a lot on the DevForums, but nothing suited the response I was hoping for. Thank you a lot for even reaching out to this post, and I will put the script down below.
local DataStoreService = game:GetService("DataStoreService")
local RobuxLeaderboard = DataStoreService:GetOrderedDataStore("RobuxLeaderboard")
local function UpdateLeaderboard()
local success, errorMessage = pcall(function()
local Data = RobuxLeaderboard:GetSortedAsync(false,5)
local RobuxPage = Data:GetCurrentPage()
for Rank, data in ipairs(RobuxPage) do
local username = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = username
local Robux = data.value
local isOnLeaderboard = false
-- SECTION, Not Working
print("works") -- landmine #1
for i,v in pairs(game.StarterGui.ScreenGui.LBFrame.Holder:GetDescendants()) do
print(v.NameLabel.Text..Name)
if v.NameLabel.Text == Name then
isOnLeaderboard = true
print("does work :palm: ")
break
end
end
-- SECTION, Not Working
print("works 2") -- pooper #1
if Robux and isOnLeaderboard == false then
print("works 3 :bruh:") -- i wanna fart rn
local NewLBFrame = script.Parent.Sample:Clone()
NewLBFrame.NameLabel.Text = Name
NewLBFrame.Visible = true
NewLBFrame.CashLabel.Text = Robux
NewLBFrame.RankLabel.Text = "#"..Rank
NewLBFrame.Position = UDim2.new(0,0,NewLBFrame.Position.Y.Scale + (.08 * #game.StarterGui.ScreenGui.LBFrame.Holder:GetChildren()))
NewLBFrame.Parent = script.Parent
end
end
end)
if not success then
print(errorMessage)
end
end
while true do
for _, Player in pairs(game.Players:GetPlayers()) do
RobuxLeaderboard:SetAsync(Player.UserId, Player.Stats.Robux.Value)
end
for _, frame in pairs(game.StarterGui.ScreenGui.LBFrame.Holder:GetChildren()) do
frame:Destroy()
end
UpdateLeaderboard()
print("Updated!")
wait(10)
end
The only reason everything but the prints within the loop would run would be because there is nothing to loop through. Print game.StarterGui.ScreenGui.LBFrame.Holder:GetDescendants() right before the loop and I’m willing to bet it will be an empty list
In fact, you’re clearing the Holder frame immediately before calling UpdateLeaderboard().
for i,v in pairs(game.StarterGui.ScreenGui.LBFrame.Holder:GetDescendants()) do
print(v.NameLabel.Text..Name)
if v.NameLabel.Text == Name then
isOnLeaderboard = true
print("does work :palm: ")
break
end
end
Theres been a NEW error message after I did what you asked lol. Down here
NameLabel is not a valid member of UIListLayout “StarterGui.ScreenGui.LBFrame.Holder.UIListLayout”, which I now get but it’s a bit confusing to clear up