Global leaderboard error

  1. What do i want to achieve?
    I want to make a global leaderboard script

  2. What is the issue?
    I am getting this warning:
    Infinite yield possible on 'Workspace:WaitForChild(“LeaderboardOOFS”)

This is the script i used:

local contentProvider = game:GetService("ContentProvider")

local leaderbaord = game.Workspace:WaitForChild("LeaderboardOOFS")

local SurfaceGui = script.Parent
local sample = script:WaitForChild("Sample")
local sf = SurfaceGui:WaitForChild("ScrollingFrame")
local ui = sf:WaitForChild("UI")
local Players = game:GetService("Players")

local dataStoreService = game:GetService("DataStoreService")
local ds = dataStoreService:GetDataStore("oofsLeaderboard")

wait(1)

while true do
	for i, plr in pairs(game.Players:GetChildren()) do
		if plr.UserId > 0 then
			local w = plr.leaderstats.OOFS.Value
			if w then
				pcall(function()
					ds:UpdateAsync(plr.UserId,function(oldval)
						return tonumber(w)
					end)
				end)
			end
		end
	end
	local smallestFirst = false
	local numberToShow = 100
	local minValue = 1
	local maxValue = 10e30
	local pages = ds:GetSortedAsync(smallestFirst,numberToShow,minValue,maxValue)
	
	local top = pages:GetCurrentPage()
	local data = {}
	
	for a,b in ipairs(top) do
		local userid = b.key
		local points = b.value
		local username = "[Failed to load]"
		local s,e = pcall(function()
			username = game.Players:GetNameFromUserIdAsync(userid)
		end)
		if not s then
			warn("Error getting name for"..userid.."Error: "..e)
		end
	end
	ui.Parent = script
	sf:ClearAllChildren()
	ui.Parent = sf
	for number, d in pairs(data) do
		local name = d[1]
		local val = d[2]
		local color = Color3.new(1,1,1)
		id = Players:GetUserIdFromNameAsync(name)
		if number == 1 then
			color = Color3.new(1,1,0)
		elseif number == 2 then
			color = Color3.new(0.666667, 0.666667, 0.666667)
		elseif number == 3 then
			color = Color3.new(0.552941, 0.305882, 0)
		end
		local new = sample:Clone()
		
		new.name = id
		new.LayoutOrder = number
		new.ImageLabel.playerName.Text = name
		new.ImageLabel.rank.Text = "#"..number
		new.ImageLabel.renk.TextColor3 = color
		new.ImageLabel.value.Text = val
		new.ImageLabel.value.TextColor3 = color
		new.ImageLabel.playerName.TextColor3 = Color3
		new.Parent = sf

	end
	wait(180)
	
	
end

Well, based on the error the script is looking for an instance called “LeaderboardOOFS” to be created in the game.Workspace location, so can you verify this instance ever gets created?

2022-12-24 (2)

this is how i arranged the leaderboards in the workspace how can i edit this line so i wont get the same error

local leaderbaord = game.Workspace:WaitForChild(“LeaderboardOOFS”)

So when you specify

local leaderbaord = game.Workspace:WaitForChild(“LeaderboardOOFS”)

it’s looking in the top most level “Workspace”, see in your picture, but your “LeaderboardOOFS” exists inside Map1 > Leaderboards, so you need to specify to look inside of Leaderboards location

local leaderbaord = game.Workspace.Map1.Leaderboards:WaitForChild(“LeaderboardOOFS”)

now i am getting this error:
GetSortedAsync is not a valid member of DataStore “DataStoreService.oofsLeaderboard”

on this line:

	local pages = ds:GetSortedAsync(smallestFirst,numberToShow,minValue,maxValue)

i think i am getting this error because of this line:

local ds = dataStoreService:GetDataStore("oofsLeaderboard")

You’ll want to have local ds be a OrderedDataSet in order to utilize the GetSortedAsync function

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.