How to fix leaderboard not working?

I made a global leaderboard in my game which displays the player with most Gems (a currency in my game) with DevKing’s leaderboard tutorial but it doesn’t work. Here’s an ss of the explorer
whyyyyyyyyyyy
and here’s the script

local DataStoreService = game:GetService("DataStoreService")
local GemsLeaderboard = DataStoreService:GetOrderedDataStore("GemLeaderboard")
local LastPosition = UDim2.new(0.5,0,0.07,0)
local Leaderboard = workspace.Lands.Forest.GlobalLeaderboard.LeaderboardGui.Holder

local function updateLeaderboard()
    local success, errorMessage = pcall (function()
        local Data = GemsLeaderboard:GetSortedAsync(false, 5)
        local GemsPage = Data:GetCurrentPage()
        for Rank, data in ipairs(GemsPage) do
               local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
               local Name = userName
               local Gems = data.value
               local isOnLeaderboard = false
            for i, v in pairs(Leaderboard:GetChildren()) do
               if v.Player.Text == Name then
                    isOnLeaderboard = true
                    break
               end
            end

             if Gems and not isOnLeaderboard then
                local newLbFrame = game.ServerStorage.LeaderboardTemplate:Clone()
                newLbFrame.Player.Text = Name
                newLbFrame.Gems.Text = Gems 
                newLbFrame.Rank.Text = Rank
                newLbFrame.Parent = Leaderboard
				if #Leaderboard:GetChildren() == 0 then
					newLbFrame.Position = LastPosition
					LastPosition = UDim2.new(0.5,0,0.07,0)
				else
					newLbFrame.Position = UDim2.new(0.5,0,LastPosition.Y.Scale + 0.13,0)
					LastPosition = UDim2.new(0.5,0,LastPosition.Y.Scale + 0.13,0)
				end
             end
          end
      end)

	if not success then
		print(errorMessage)
	end

end

while true do
    for _, player in pairs(game.Players:GetPlayers()) do
          GemsLeaderboard:SetAsync(player.UserId, player.leaderstats.Gems.Value)
    end

    for _, frame in pairs (Leaderboard:GetChildren()) do 
          frame:Destroy()
    end

    updateLeaderboard()
    print("Leaderboard Updated!")

    wait(160)
end

It just prints out “Leaderboard Updated!” and thats all (w/ no errors at all)

Maybe you can send a model of it? That will save a lot of time.

Have you made sure that the Enable Studio Access to API Services option is enabled?

image

1 Like

Dizzy leaderboard.rbxm (9.8 KB)

you named your leaderstats “Leaderstats” (capital L) right? And in the while loop It will search for a folder named “leaderstats” (small L) inside player thats why it prob didnt work

TRY THIS:
Enable this option: “Enable Studio Access to API Services”

ScreenShot6_Heply

To activate this feature, go to “Develop” Page, and then search your game and click on “Configure Game” and activate this option.

Second Method:
Try this script, configure some items and place the Frame (where the “IbFrame” player table) in ReplicatedStorage, and put the name of your game’s Leaderstats.

local CashODS = game:GetService(“DataStoreService”):GetOrderedDataStore(“CashSaveODS”)

local function Handler()
local Success, Err = pcall(function()
local Data = CashODS:GetSortedAsync(false, 5)
local CashPage = Data:GetCurrentPage()
for Rank, Data in ipairs(CashPage) do
local Name = Data.key
local Cash = Data.value
local NewObj = game.ReplicatedStorage:WaitForChild(“PutYourPlayerFrameHere”):Clone()
NewObj.Player.Text = Name
NewObj.Cash.Text = Cash – Put your “Cash” Text name here.
NewObj.Rank.Text = “#”…Rank
NewObj.Position = UDim2.new(0, 0, NewObj.Position.Y.Scale + (0.08 * #game.Workspace.GlobalLeaderboard.lbGUI.Holder:GetChildren()), 0)
NewObj.Parent = game.Workspace.GlobalLeaderboard.lbGUI.Holder
end
end)
if not Success then
error(Err)
end
end

while true do
for _,Player in pairs(game.Players:GetPlayers()) do
CashODS:SetAsync(Player.Name, Player.leaderstats.Cash.Value) – Put your Leaderboard Name.
end
for _,v in pairs(game.Workspace.GlobalLeaderboard.lbGUI.Holder:GetChildren()) do
if v.Name == “lbFrame” then
v:Destroy()
end
end
Handler()
wait(10) – Interval Updates
end

And put in “ServerScriptService”.

2 Likes