Before I start, please note that I want to be explained the answer, not just spoonfed. I want to actually learn from this mistake. Please keep that in mind.
I’ve been working on a Global Leaderboard for my game, K-Pop hangout. After watching a tutorial from @UseCode_Tap, I thought that I understood
OrderedDataStores. However, this is the error I keep getting:
I’ve tried a few diffrent solutions with no luck. Here is my code:
local DataStoreService = game:GetService("DataStoreService")
local WinsLeaderboard = DataStoreService:GetOrderedDataStore("timeDataStore".."-time")
local function updateLeaderboard()
local success, errorMessage = pcall(function()
local Data = WinsLeaderboard:GetSortedAsync(false, 5)
local WinsPage = Data:GetCurrentPage()
for Rank, data in ipairs(WinsPage) do
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = userName
local Time = data.value
local isOnLeaderboard = false
for i, v in pairs (game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()) do
if v.Player.Text == Name then
isOnLeaderboard = true
local userName = Data.key
if Time and isOnLeaderboard == false then
local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
newLbFrame.Player.Text = Name
newLbFrame.Time.Text = Time
newLbFrame.Rank.Text = "#"..Rank
newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + .08 * #game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren(), 0)
newLbFrame.Parent = game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder
if not success then
while true do
for _, player in pairs (game.Players:GetPlayers()) do
WinsLeaderboard:SetAsync(player.UserId .. "-time", player.leaderstats.TimePlayed.Value)
for _, frame in pairs (game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()) do
Here is workspace, just in case:
Data saves fine, datastores are seeminly not the issue. I think I might be using
Again, I am a novice scripter, so I would like to be explained the solution, not just spoonfed.
did you mean to put an = between these? It’s saying there’s a problem with WinsPage in your ipairs loop so this is likely the issue .
That fixed the original error, now I am getting this:
(Cannot believe I overlooked that!)
When you click on it, does it redirect you to one of the scripts and the line the error has occurred on? Thank you, that would help
Line 36 of LeaderboardHandler, specifically:
if not success then
OK, this may be the line that’s causing the problem - maybe, I’m not an expert at DataStores. Try removing the “-time” bit at the end, I think that if you include that, it’s trying to define a DataStore called “timeDataStore-time”, so this could be the problem that’s then causing it to not work.
-time is the specific key I am using, it’s better to have one datastore with different keys. (Correct me if I’m wrong about that).
Another typo? Did you mean game.Workspace.GlobalLeaderboard?
You’re probably right, I usually make a separate datastore for everything because I’m overly complicating
Still didn’t fix it, however probably fixed another error somewhere along the lines.
I need to be more careful!
OK, just been reading through the developer pages on OrderedDataStores.
Here, try it just with:
local userName = data.key
See what it comes up with - if it doesn’t print anything at all, then something before the ipairs loop has gone wrong.
I’ve also got a feeling there’s something wrong with the ‘Rank’ part, which could relate to that Argument 1 missing/nil error. I’ll have a check through that.
Your theory was right, nothing printed.
Update: Still having issues, looked through my code and I cannot figure out why. Help is appreciated.
Updated this post with the new code, still not working.
Is there Data in the Data store?
Yes. There is data of around 5 people.
Hmm try setting some different fake users using :SetAsync()
You can remove them later
tell me if it works
It doesn’t make a difference. Per the tutorial I used, it should work even with one person.
Sorry for being late
But im going to test your code to see if it works give me a moment