Global leaderboard position issue

image
Console Spamming this issue and position dont work :skull:

Here script

local datastoreKey = "GlobalCash"
local datastore = game:GetService('DataStoreService'):GetOrderedDataStore(datastoreKey)
local PlayerService = game:GetService("Players")
local remote = game:GetService('ReplicatedStorage'):WaitForChild('Tag')
local currentTopHundred = {}

local function PlayerLoop(player)
		
	coroutine.wrap(function()
		local debounce = false
		while player and player.Parent and debounce == false do
			debounce = true
			if not player.Parent then
				break
			end
			
			local save = player:WaitForChild('leaderstats'):WaitForChild('Cash')
			 
			datastore:SetAsync(player.UserId, save.Value)
			task.wait(59)
			debounce = false
		end
	end)()
	
end

local function Clientloop()
	coroutine.wrap(function()
		while true do
			currentTopHundred = {}
			local pages = datastore:GetSortedAsync(false, 100)
			local topPage = pages:GetCurrentPage()
			for i,data in pairs(topPage) do
						table.insert(currentTopHundred,{
							userID = data.key,
							value = data.value
						})
				end
			end
			
			task.wait(60)
		end)()
end

Clientloop()

remote:OnServerEvent:Connect(function(player)
for position,data in pairs(currentTopHundred) do
		if data[1] == player.UserId then
			print(position)
			return position
		else
			continue
		end
	end
end

game.Players.PlayerAdded:Connect(PlayerLoop())
for _, player in ipairs(game.Players:GetPlayers()) do
	PlayerLoop(player)
end
2 Likes

Well, there’s not much you can do about it considering you want it to save data ~every 60 seconds. It’s just a warning that if you do it too much it will stop working. You can add more time between saves, but that’s about it.

1 Like

How many minutes? :::::::::::::::::::::::::::::::::::::::::::::::::::::

1 Like

I suggest you save data when the player leaves or the server shuts down.

1 Like

It’s not a leaderstats data script I Wanted refresh leaderboard every minute

1 Like

Just make it so the player’s data is only updated to the leaderboard whenever they leave the game, the leaderboard doesn’t need to have pinpoint accuracy. You could also just have it update every 3-5 minutes instead so it doesn’t overload the datastore. My bad for the late reply

2 Likes