I am modifying my old leaderboard script because it relied on Playerpoints and those are no longer being used. I got this weird error Argument 2 missing or nil on line 28. I dont know too much about datastores so Idk whats going wrong.
Heres the whole script.
local PAGE_SIZE = 50
local dsService = game:GetService("DataStoreService")
local ODS = game:GetService("DataStoreService"):GetOrderedDataStore("HighScore")
local leaderboard = ODS:GetSortedAsync(false, PAGE_SIZE):GetCurrentPage()
function sort(x, y)
-- Return comparison
return (x[2] > y[2])
end
game.ReplicatedStorage.Interactions.Server.GetLeaderboardPlayers.OnServerInvoke = function(plr, global)
-- Check if global
if global then
return leaderboard
else
-- Get player points of each player
local points = {}
local queue = 0
for _, i in pairs(game.Players:GetChildren()) do
queue = queue + 1
spawn(function()
table.insert(points, {i.UserId, ODS:GetSortedAsync(i.UserId)})
queue = queue - 1
end)
end
repeat
wait()
until queue <= 0
-- Sort table
table.sort(points, sort)
-- Return table
return points
end
end
while wait(90) do
-- Set pages for the player point data store
leaderboard = ODS:GetSortedAsync(false, PAGE_SIZE):GetCurrentPage()
end

2 comments
To prevent the error try replacing the spawn function with a pcall function which won't return any errors.
bad idea