Help With Leaderboard

I am trying to make a globe leaderboard like this

When I play in studio or in game nothing comes up how do I fix it

Location of script
Screenshot 2023-07-16 at 12.46.02

local DataStoreService = game:GetService("DataStoreService")
local PartsDataStore = DataStoreService:GetOrderedDataStore("PartsLeaderboard")

local LeaderboardPart = script.Parent.Parent.Parent
local RefreshRate = 10

local function RefreshLeaderboard()
	
	for i, Player in pairs(game.Players:GetPlayers()) do
		PartsDataStore:SetAsync(Player.UserId, Player.leaderstats.Parts.Value)
	end
	
	local Success, Error = pcall(function()
		
		local Data = PartsDataStore:GetSortedAsync(false, 10)
		local PartsPage = Data:GetCurrentPage()
		
		for Rank, SavedData in ipairs(PartsPage) do
			
			local Username = game.Players:GetNameFromUserIdAsync(tonumber(SavedData.key))
			local Parts = SavedData.value
			
			if Parts then
				
				local NewSample = script.Parent.Sample:Clone()
				
				NewSample.Visible = true
				NewSample.Parent = LeaderboardPart.SurfaceGui.PlayerHandler
				NewSample.Name = Username
				
				NewSample.RankLabel = "#"..Rank
				NewSample.NameLabel = Username
				NewSample.PartsLabel = Parts
			end
		end
	end)
end

while true do
	
	for	i, Frame in pairs(LeaderboardPart.SurfaceGui.PlayerHandler:GetChildren()) do
		if Frame.Name ~= "Simple" and Frame:IsA("Frame") then	
			Frame:Destroy()
		end
	end
	
	RefreshLeaderboard()
	wait(RefreshRate)
end
3 Likes

Looking at it, you’re using a server script inside the client. Something you can’t do. Change the server script to a client script.

This show up but it does not show the info
Screenshot 2023-07-16 at 13.06.08

Here is the video I used

What type of leaderboard are you attempting to make?

Globe Leaderboard (for the amount of Parts a player has)

1 Like

Hm, so it’s supposed to show a list of all players and how much parts they have?

Corect ------------------------

1 Like

Okay so you’d need to make it so if a player has joined they’d automatically be added to the leaderboard, right. Then you’d need to make it so it automatically updates the amount of parts they have.

How do I do that in the script

Change “for i, Player in pairs(game.Players:GetPlayers()) do” to game.Players.PlayerAdded:Connect(function(Player)

And so this would become,

game.Players.PlayerAdded:Connect(function(Player)
PartsDataStore:SetAsync(Player.UserId, Player.leaderstats.Parts.Value)
end

By the way, I’m not completely sure if this will work or not but if it does then please let me know.

I did not work is there another way

An error come up
leaderstats is not a valid member of Player “Players.Cyber_Designer”

Did you add an ) next to end like it is shown below?

game.Players.PlayerAdded:Connect(function(Player)
PartsDataStore:SetAsync(Player.UserId, Player.leaderstats.Parts.Value)
end)

Oh, that may be why it isn’t working then. Check if there is a leaderstats under the player.

Ya leaderstats are part of the player

Can you screenshot it and send it here?

Ya here you go
Cool.rbxl (53.8 KB)

I am testing it out now and I will try to fix it for you.