Everything is working fine except the datastore is returning nil for the value even though it is set as 1 in the update function.

for i = 1,11 do
	local Sam = script.Sample:Clone()
	Sam.Name = i
	Sam.Parent = script.Parent.ScrollingFrame
	Sam.UserPos.Text = "[".. tostring(i) .. "]"
	Sam.score.Text = "Nill"
	Sam.UserName.Text = ""
	Sam.LayoutOrder = i
end



function UpdateGui()
	for i,v in pairs(game.Players:GetChildren()) do
		local Data = 1
		local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("ScoreX1")
		DataStore:IncrementAsync(v.UserId,Data)
	end
	local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("ScoreX1")
	local Pages = DataStore:GetSortedAsync(false,10)
	local Data = Pages:GetCurrentPage()
	for k,v in pairs(Data) do
		if tonumber(v.key) >= 1 then
			local Frame = script.Parent.ScrollingFrame:FindFirstChild(tostring(k))
			if Frame then
				Frame.UserName.Text = game.Players:GetNameFromUserIdAsync(v.key)
				print(game.Players:GetNameFromUserIdAsync(v.key))
				print(v.Value)
				Frame.score.Text = tostring(v.Value)
			end
		end
	end
end

while true do
	UpdateGui()
	wait(2)
end

8 comments

0

why do you need to do that every 2 seconds

0

^ too many requests. Think more about what needs to do done and how often.

0

I update my global leaderboards every two minutes. I don't recommend updating global leaderboards for less than every 20-30 seconds.

0

Hope these links help you out!

0

You're updating your values too often, update it and save it every time the Player leaves, you can simply do this with 'game.Players.PlayerRemoved:Connect(function()' then add the function(UpdateGui) inside of that function.