-- [[ Dummiez's Data Store Score Board ]]
-- This script updates the Data store with the values from the remote function.


wait(1)

local ods = game:GetService("DataStoreService"):GetOrderedDataStore("TopCoins")

function updateBoard(board, data)
	for k,v in pairs(data) do
		local pos = k
		local name = v.key
		local score = v.value
		local dispname = board:findFirstChild("Name"..pos)
		local dispval = board:findFirstChild("Score"..pos)
		dispname.Text = tostring(name)
		dispval.Text = tostring(score)
	end	
end

while true do
	wait(script.Refresh.Value)
	local pages = ods:GetSortedAsync(false, 10)
	local data = pages:GetCurrentPage()
	updateBoard(game.Workspace.HighScore.ScoreBlock.SurfaceGui, data)
end
