In workspace

function script.UploadScore.OnServerInvoke(player)
local inv = player:WaitForChild("leaderstats") -- Whatever stats
local score = game:GetService("DataStoreService"):GetOrderedDataStore("TopScores") -- Name of Data Store
score:SetAsync(player.Name, inv:FindFirstChild("KOs").Value) -- What is in the leaderstats
print("Works4")
end

In serverscriptstorage

local ods = game:GetService("DataStoreService"):GetOrderedDataStore("Scores")
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)
		print("Works1")
	end	
end

while true do
	wait(10) -- Updates every 2 minutes
	local pages = ods:GetSortedAsync(false, 10)
	local data = pages:GetCurrentPage()
	updateBoard(game.Workspace.HighScore.TopBlock.SurfaceGui, data) -- change 'game.Workspace.HighScore.TopBlock.SurfaceGui' to where it will be
	print("Works2")
end

In StarterGui

wait(5)
local player = game.Players.LocalPlayer
while true do
game.Workspace.UploadScore:InvokeServer()
print("Works3")
wait(10)-- How long you want to usend
end

It dosent want to work. I have set a print so it prints something when it has started working. It only prints Works2 for some reason. I dont know whats wrong. Someone please help.