Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Argument 2 Missing or Nil How do I fix it?

Asked by 4 years ago
Edited 4 years ago

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
0
To prevent the error try replacing the spawn function with a pcall function which won't return any errors. Dalbertjdplayz 37 — 4y
0
bad idea Fifkee 2017 — 4y

Answer this question