-
What do i want to achieve?
I want to make a global leaderboard script -
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