--[[ if your changing the DataStore name from LB 
		to anything else you should change it 
		inside the LeaderboardHandler too
	]]
--
local leaderboardDS =  ds:GetOrderedDataStore("LB")


players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local Cash = Instance.new("NumberValue")
	Cash.Name = "Cash"
	Cash.Parent = leaderstats
	
	local Coins = Instance.new("NumberValue")
	Coins.Name = "C"
	Coins.Parent = leaderstats
	
end)


while true do
	
	for i , v in pairs(players:GetPlayers()) do
		local succ , errmsg = pcall(function()
			-- saving the Coins value with the player's userid as the key
			leaderboardDS:SetAsync(v.UserId , v.leaderstats.Coins.Value)
		end)
	end	
	-- recommend waiting for a longer time
	task.wait(220)
end
