Global leaderboard not working

local DataStoreService = game:GetService("DataStoreService")
local ActivityLeaderboard = DataStoreService:GetOrderedDataStore("ActivityLeaderboard")
local function updateLeaderboard()
	local success, errorMessage = pcall(function()
		local Data = ActivityLeaderboard:GetSortedAsync(false,5)
		local ActivityPage = Data:GetCurrentPage()
		for rank, data in ipairs(ActivityPage) do
			local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Name = userName
			local Activity = 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 Activity and isOnLeaderboard == false then
				local newLBFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
				newLBFrame.Player.Text = Name
				newLBFrame.Points.Text = Activity
				newLBFrame.Rank.Text = "#"..rank
				newLBFrame.Position = UDim2.new(0,0,newLBFrame.Position.Y.Scale + (.09 * #game.Workspace.globalLeaderboard.leaderboardGui.Holder:GetChildren()),0)
				newLBFrame.Parent = game.Workspace.globalLeaderboard.leaderboardGui.Holder
			end
		end
	end)
	if not success then
		print(errorMessage)
	end
end
while true do
	for _, Player in pairs(game.Players:GetPlayers()) do
		ActivityLeaderboard:SetAsync(Player.UserId,Player:WaitForChild("leaderstats"):FindFirstChild("Activity").Value)
	end
	for _,frame in pairs(game.Workspace.globalLeaderboard.leaderboardGui.Holder:GetChildren()) do
		frame:Destroy()
	end
	updateLeaderboard()
	wait(10)
end

This doesnt add the frame to the leaderboard.

1 Like

Is your goal to create a new UI leaderboard to replace the default one, or just a leaderboard attached to a Part that displays the players stats?

a global leaderboard that displays all players stats, and it updates every 10 seconds

Well, you could’ve simply searched and found your answer! Here are a few videos and posts I’ve found, feel free to search a bit more. If this does not solve your problem, feel free to reply to this or to DM me.

AlvinBlox’s Tutorial
ThatTimothy’s Tutorial

Hope this helped, have a great rest of your day/night!

Mine was a tutorial of TheDevKing.

1 Like

It works in his video but its not working for me.

Try re-reading your code, also try checking the description for the code, sometimes your code might be written wrong. (Make sure to read it afterwards so you can learn) I’ll check your code right now.

do you see any problems in the code?

If you used datastore, it might be because of that since the datastore had some issues earlier. I’ll keep on trying to find a solution for this.

Alright, thank you. I’ll try to fix it as well.

I also noticed this, that might not be the problem, but why is a :Destroy function there? :thinking:

By now it should be fixed, I also heard that the datastore worked in studio, I’m not quite sure. I’ll watch the video myself real quick.

I destroyed it and redid it with the call of the function after that.

1 Like

Can you check if you received any errors?

1 Like

I did not recieve any errors for this script.

Check if the frames are visible or not, maybe the transparency is set to 0.
Edit: TheDevKing also mentions that you have to publish the game, check if your game is published or not, that might be the problem.

Is the actual leaderboard the same as the one in his video?

LittleJackBlocks yes, the frame is fine and I published the game. I made the leaderboard along with his video @Coldshot_Dev

Hmm, I don’t see anything wrong with the script. Are you sure its the exact script in his video? If so, the script may be outdated.

2 Likes

As @Coldshot_Dev Said, the script might be outdated, try the one I suggested that’s made by @ThatTimothy, he also has a model so you can check if it works.

1 Like