Hello,

I was following a YouTube video on how to make a global leaderboard since I have never made one before. I edited it so that it works with my game, which is probably where it broke... I want to rank players depending on their "LadderPoints" (player.leaderstats.LadderPoints).

Here is the script:

local DataStoreService = game:GetService("DataStoreService")
local LadderData = DataStoreService:GetOrderedDataStore("LadderData")

local function updateLeaderboard()
	local success, errorMessage = pcall (function()
	local Data = LadderData:GetSortedAsync(false, 5)
    local PointsPage = Data:GetCurrentPage()
    for Rank, data in ipairs(PointsPage) do
    	local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
        local Name = userName
        local Points = 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
                    break
                end
            end

            if Points and isOnLeaderboard == false then
           		local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
                newLbFrame.Player.Text = Name
                newLbFrame.Points.Text = Points 
                newLbFrame.Rank.Text = "#"..Rank
                newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.11 * #game.Workspace.GlobalLeaderboard.TextPart.LeaderboardGUI.Holder:GetChildren()), 0)
                newLbFrame.Parent = game.Workspace.GlobalLeaderboard.TextPart.LeaderboardGUI.Holder
    		end
		end
	end)

    if not success then
		print(errorMessage)
	end
end

while true do

    for _, player in pairs(game.Players:GetPlayers()) do
		LadderData:SetAsync(player.UserId, player.leaderstats.LadderPoints.Value)
    end

    for _, frame in pairs(game.Workspace.GlobalLeaderboard.TextPart.LeaderboardGUI.Holder:GetChildren()) do
    	frame:Destroy()
    end

    updateLeaderboard()
    print("Updated!")

	wait(30)
end

Thank you!!

4 comments

0

Next time, don't just paste in a code and telling us it's from a youtube video expecting us to know immediately what's the problem is. What isn't working? Have you tried debugging it? (printing every few lines) Is there an output?

0

I think the issue is the datastore. The script isn't finding any data from "LadderData," when I try to print out the User's name, nothing happens; not even an error. (Line 09)

0

Alright.