Hey, so i've got this script. It works, for the first 2 ranks to load. However, when doing the third round in "for Rank, data in ipairs(WinsPage) do" it returns -1 as data.key

local DataStoreService = game:GetService('DataStoreService') -- WAS local DataStoreService = game:GetService('DataStoreService')
local leaderboardData = DataStoreService:GetOrderedDataStore('MainPlayerData1') -- WAS: local leaderboardData = DataStoreService:GetOrderedDataStore('LeaderStats')

local function updateLeaderboard()
	wait()
	local success, errorMessage = pcall (function()
	local Data = leaderboardData:GetSortedAsync(false, 10)
		local WinsPage = Data:GetCurrentPage()
		wait()
		for Rank, data in ipairs(WinsPage) do
			wait()
			warn('Data.Key = ',data.key)
			local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))			
			local Name = userName			
			local Wins = data.value			
			local isOnLeaderboard = false			
			for i, v in pairs(game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()) do				
				if v.B2.Player.Text == Name then					
					isOnLeaderboard = true					
					wait()				
				end				
			end			
			if Wins and isOnLeaderboard == false then				
				local newLbFrame = game.ReplicatedStorage:FindFirstChild('LeaderboardFrame'):Clone()
				newLbFrame.B2.Player.Text = Name
				newLbFrame.B3.Wins.Text = Wins 
				newLbFrame.B1.Rank.Text = '#'..Rank
				newLbFrame.Position = UDim2.new(0.5, 0, newLbFrame.Position.Y.Scale + (.10 * #game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()), 0)
				newLbFrame.Parent = game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder
				print('Added Rank #',Rank,' to the leaderboard')
			end
		end
	end)
	if not success then
		warn('ERROR ON LEADERBOARD: ',errorMessage)
	end
end

However, i'm not the creator of this script. And i don't know how i've got it. It has been in my inventory for age's.

This is the output i get:

  01:03:57.159 - Data.Key =  1914533814
  Added Rank # 1  to the leaderboard
  01:03:57.304 - Data.Key =  136220092
  Added Rank # 2  to the leaderboard
  01:03:57.459 - Data.Key =  -1
  01:03:57.558 - ERROR ON LEADERBOARD:  Players:GetNameFromUserId() failed because HTTP 404 (NotFound)

I don't know how to fix it, neither what the error means in so far. I guess there's something wrong with the Key? (PlayerID)?

2 comments

0

Roblox had a maintenance issue. Might be fixed now.

0

Rule on scripting helpers: Attempts should be your own work. Don't take a free model and expect us to fix it. View it here for yourself at https://scriptinghelpers.org/help/community-guidelines under Website Guidelines.