Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my Global Leaderboard update on studio, but not on a server?

Lets start off with the code to get the code in your mind.

ods = game:GetService("DataStoreService"):GetOrderedDataStore("BinaryBashGlobalLeaderboardLevels")

function updateBoard(board, data)
	for index, child in ipairs(data) do
		local pos = index
		local name = child.key
		local score = child.value
		local dispname = board.PlayerNames:FindFirstChild("Name"..pos)
		local dispval = board.PlayerScores:FindFirstChild("Score"..pos)
		dispname.Text = tostring(name:sub(8)) 
		dispval.Text = tostring(score)
	end
end

coroutine.resume(coroutine.create(function()
  while wait((5 + game.Players.NumPlayers * 2)/60) do
    local pages = ods:GetSortedAsync(false, 10)
    local data = pages:GetCurrentPage() 
    updateBoard(script.Parent.Leaderboard, data)
  end
end))

print("Still running after the loop! Woo!")
while wait((60 + game.Players.NumPlayers * 10)/60) do
  	for i, plr in pairs (game.Players:GetChildren()) do
			local key = "player-" .. plr.Name
  		local newStat = plr.leaderstats.Levels.Value
 			ods:SetAsync(key, newStat)
  	end
end

The issue is whenever I test this in studio, the Global Leaderboard updates relatively quick. I use the algorythms from the Roblox Wiki that tell me the limitations for the speed the Global Leaderboard can update per minute per server.

The momment I go into a server, it says that it is updating, no errors, but - It doesn't update.

Whoever knows the issue please answer this!

EDIT: I just logged onto a server, but since this is a new server the leaderboard is up-to-date. So the script works once??? I just thought I would let you guys know incase there would be a different issue.

Sincerely, jmanrock123

P.S: Thanks to whoever helped in advance!

1 answer

✓ Accepted answer

Change the wait in the coroutine on line 16 to

wait(60/(8+game.Players.NumPlayers * 1.5))

this should keep the data store service from screaming at you for not giving it enough time to breath.

This discussion is preserved as it was. New answers, comments, and votes are closed.