Help with using SetAsync for a DataStore

Hello roblox community, this is a Global Leaderboard script, I get an error on line 35:
‘PointsLeaderboard:SetAsync(player.UserId,currency)’
but I have tried all the ways and it doesn’t work, please.

Script, “ServerScriptService”:

local DataStore = game:GetService('DataStoreService')
local PointsLeaderboard = DataStore:GetOrderedDataStore('JuanesTeban')

local function updatePointsLeaderboard()
	local succes, errorMessage = pcall(function()
		local Data = PointsLeaderboard:GetSortedAsync(false,5)
		local WinsPage = Data:GetCurrentPage()
		for Rank, data in pairs(WinsPage) do
			local UserName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Name = UserName
			local Points = data.Value
			local isOnLeaderboard = false
			for i,v in pairs(game:GetService('Workspace').TopLeaderstatsPoints.TopLeaderboard:GetChildren()) do
				if v.TOPPOINTS.Visible == true then
					isOnLeaderboard = true
					break
				end
			end
			if Points and isOnLeaderboard == false then
				local ListaJugadoresClone = game:GetService('ReplicatedStorage'):WaitForChild('ListaJugadores'):Clone()
				ListaJugadoresClone.Jugador.Text = Name
				ListaJugadoresClone.POINTS.Text = Points
				ListaJugadoresClone.Puesto.Text = Rank
				ListaJugadoresClone.Parent = game:GetService('Workspace').TopLeaderstatsPoints.Scrolling
			end
		end
	end)
	if not succes then
		print(errorMessage)
	end
end
while true do 
	for _,player in pairs(game.Players:GetPlayers()) do
		local currency = player.leaderstats.Points.Value
		PointsLeaderboard:SetAsync(player.UserId,currency)
	end
	updatePointsLeaderboard()
	wait(5)
end
2 Likes

do `PointsLeaderboard:SetAsync(player.UserId…currency)’

1 Like

That’s wrong, bro You cannot put three dots, it would be a typing error.

i typed 3 dots by accident…

Still not working, with 2 or 3 points in a row.

try to do PointsLeaderboard:SetAsync(player.UserId…“-currency”,currency)

PointsLeaderboard:SetAsync(player.UserId…“-currency”,currency)

mm doesn’t work either bro

1 Like

Sorry then im not sure, im not that good with datastore yet.

oh okay, :frowning: it really will be difficult

Hello do you have the full error about line 35 exactly??

Hi, exactly I get an error on line 35 = ‘PointsLeaderboard:SetAsync(player.UserId,currency)’

There is no description about the error? Usually they should have a description as to why it was not working. either incorrect syntax or missing arguments

oh I got it, I didn’t have the API enabled, but I enabled it and it still doesn’t work and I get this error again…

Oh, your just doing to many requests. Edit: my bad there is another error message.

It says the item “TOPPOINTS” is not a valid member of the hierarchy. try fixing your hierarchy in the script

Ok, I tried to solve it but I get a problem and it is in line 29 = ‘print(errorMessage)’

local DataStore = game:GetService('DataStoreService')
local PointsLeaderboard = DataStore:GetOrderedDataStore('JuanesTeban')

local function updatePointsLeaderboard()
	local succes, errorMessage = pcall(function()
		local Data = PointsLeaderboard:GetSortedAsync(false,5)
		local WinsPage = Data:GetCurrentPage()
		for Rank, data in pairs(WinsPage) do
			local UserName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Name = UserName
			local Points = data.Value
			local isOnLeaderboard = false
			for i,v in pairs(game:GetService('Workspace').TopLeaderstatsPoints.TopLeaderboard:GetChildren()) do
				if v.TOPPOINTS.Visible == true then
					isOnLeaderboard = true
					break
				end
			end
			if Points and isOnLeaderboard == false then
				local ListaJugadoresClone = game:GetService('ReplicatedStorage'):WaitForChild('ListaJugadores'):Clone()
				ListaJugadoresClone.Jugador.Text = Name
				ListaJugadoresClone.POINTS.Text = Points
				ListaJugadoresClone.Puesto.Text = Rank
				ListaJugadoresClone.Parent = game.Workspace.TopLeaderstatsPoints.Scrolling
			end
		end
	end)
	if not succes then
		print(errorMessage)
	end
end
while true do 
	for _,player in pairs(game.Players:GetPlayers()) do
		local currency = player.leaderstats.Points.Value
		PointsLeaderboard:SetAsync(player.UserId,currency)
	end
	updatePointsLeaderboard()
	wait(5)
end

Could you give the full error message instead of just the line where the error is?

It is the same error but I do not understand if all your locations are correct.

Screenshot_28

Fix your hierarchy, your script could not find “TOPPOINTS”

your print(errorMessage) is not the problem. It’s simply printing the error (script not being able to find TOPPOINTS in the hierarchy you placed on the script)