What is the issue about this global leaderboard script?

Hello, I’m OriginalDevelops! I’m trying to make a Global Leaderboard script, but it didnt work :disappointed_relieved:. I’ve trying to fix it but it didn’t, I couldn’t fix it… So I want you to help me to see what is the issue of my script below and help me fix it ! My Script ( Server Script ) ::

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

local function updateLeaderboards()
	local success, errormessage = pcall(function()
		local Data = StrengthLeaderboards:GetSortedAsync(false, 5)
		local strengthPage = Data:GetCurrentPage()
		for Rank, data in ipairs(strengthPage) do
			local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Name = userName
			local strength = data.Value
			local isOnLeaderboard = false
			for i, v in pairs(game.Workspace.Lobby.StrengthLeaderboard.Leaderboard.Holder:GetChildren()) do
				if v.Player.Text == Name then
					isOnLeaderboard = true
					break
				end
			end
			
				if strength and isOnLeaderboard == false then
					local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
					newLbFrame.Name.Text = Name
					newLbFrame.Total.Text = strength
					newLbFrame.Rank.Text = "#"..Rank
					newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (0.8 * #game.Workspace.Lobby.StrengthLeaderboard.Leaderboard.Holder:GetChildren()), 0)
					newLbFrame.Parent = game.Workspace.Lobby.StrengthLeaderboard.Leaderboard.Holder
			end	
		end
	end)
		
		if not success then
			print(errormessage)
		end
	end
	
while wait(30) do
	 
	for _, player in pairs(game.Players:GetPlayers()) do
		StrengthLeaderboards:GetAsync(player.UserId, player.Stats.Strength.Value)
	end
	
	for _, frame in pairs(game.Workspace.Lobby.StrengthLeaderboard.Leaderboard.Holder:GetChildren()) do
		frame:Destroy()
	end
	
	updateLeaderboards()
	print("Updated!")

	
end

You are destroying the frames inside the “While wait(30) do” loop, which results in the updateLeaderboards() function not being able to find any frame to hold it’s data in the first place.

1 Like

I’ve tried wait(30) but it didnt work too?

This part right here;

	for _, frame in pairs(game.Workspace.Lobby.StrengthLeaderboard.Leaderboard.Holder:GetChildren()) do
		frame:Destroy()
	end

That’s what is causing the problem.

So what things I’m going to do? Can you give me an example?

And why it still print out “Update!” ? :confused:

Do you get any errors in your Output while running the code? If the answer is yes please send them in here so that we can help you fix it.

There is no error in the output…

Found the problem it is on line 11 data.Value should be data.value since data.Value is nill.

I’ve tried that, the script still not working :disappointed_relieved:

Did you set StrengthLeaderboards in an other script because here you are only use get requests?

If you did not you need to change
StrengthLeaderboards:GetAsync(player.UserId, player.Stats.Strength.Value)
to
StrengthLeaderboards:SetAsync(player.UserId, player.Stats.Strength.Value)


while wait(30) do
	 
	for _, player in pairs(game.Players:GetPlayers()) do
		StrengthLeaderboards:GetAsync(player.UserId, player.Stats.Strength.Value)
	end
	
	for _, frame in pairs(game.Workspace.Lobby.StrengthLeaderboard.Leaderboard.Holder:GetChildren()) do
		frame:Destroy()
	end
	
	updateLeaderboards()
	print("Updated!")

	
end

You tell it to in the last line of the while loop, so it prints every 30 seconds.

I didnt, maybe I will try it tomorrow :neutral_face: