im trying to make a in-game Global Leaderboard, that show's a players Win - Loss record, apparently there's no exact way to do this properly, or yet that i've found out.
but im trying this method, and im pretty sure it'll work, but I get this error "Attempt to Index Number with Number (Line 24)"
Here's the code:
local UpdateVersion = '.455'
local LBWinStats = game:GetService("DataStoreService"):GetOrderedDataStore("Leaderboard_WinStats_UpdateV:"..UpdateVersion)
local LBLossStats = game:GetService("DataStoreService"):GetOrderedDataStore("Leaderboard_LossStats_UpdateV:"..UpdateVersion)
local refresh = 20 -- keep above 20
print('Current Leaderboard Update Version V'..UpdateVersion)
local function Handler()
local Success, Err = pcall(function()
local WinData = LBWinStats:GetSortedAsync(false, 25)
local WinPage = WinData:GetCurrentPage()
for WinRank, WinData in ipairs(WinPage) do
local Name = WinData.key
local wins = WinData.value
local loss = LBLossStats:GetAsync(Name)
local NewObj = game.ReplicatedStorage:WaitForChild("lbFrame"):Clone()
if WinRank == 1 then
NewObj.Rank.TextColor3 = Color3.new(255, 170, 0)
NewObj.Player.TextColor3 = Color3.new(255, 170, 0)
NewObj.Cash.TextColor3 = Color3.new(255, 170, 0)
elseif WinRank == 2 then
NewObj.Rank.TextColor3 = Color3.new(255, 170, 0)
NewObj.Player.TextColor3 = Color3.new(255, 170, 0)
NewObj.Cash.TextColor3 = Color3.new(255, 170, 0)
elseif WinRank == 3 then
NewObj.Rank.TextColor3 = Color3.new(255, 170, 0)
NewObj.Player.TextColor3 = Color3.new(255, 170, 0)
NewObj.Cash.TextColor3 = Color3.new(255, 170, 0)
end
NewObj.Player.Text = Name
NewObj.Cash.Text = wins..'-'..loss[1]
NewObj.Rank.Text = "#"..WinRank
NewObj.Position = UDim2.new(0, 0, NewObj.Position.Y.Scale + (0.032 * #game.Workspace.GlobalLeaderboard.lbGUI.ScrollingFrame:GetChildren()), 0)
NewObj.Parent = game.Workspace.GlobalLeaderboard.lbGUI.ScrollingFrame
end
end)
if not Success then
error(Err)
end
end
while true do
wait(refresh)
for _,v in pairs(game.Workspace.GlobalLeaderboard.lbGUI.ScrollingFrame:GetChildren()) do
if v.Name == "lbFrame" then
v:Destroy()
end
end
for _,Player in pairs(game.Players:GetPlayers()) do
LBWinStats:SetAsync(Player.Name, Player.Stats.Wins.Value)
LBLossStats:SetAsync(Player.Name, Player.Stats.Losses.Value)
end
Handler()
wait(refresh)
end
if anyone could figure out the solution, that would be great.

2 comments
What's the loss[1] for? Is it a table or a number?
ill edit and put the full code of the script. but the script has a refresh timer, that saves to the DataStore every 60 seconds, of the player's in-game Data (wins, losses) the WinsDataStore, saves wins, LossDataStore, saves Losses (for some reason I have to use two DataStores for this to work.)