DataStore does not load in and makes an error

I want to load in my datastore info, but when I’m tryng to import it into a atble it makes an error that says something that isn’t even inside the script.
The function is triggerd by a remoteFunction form in replicated storage which gets activated by a localscript.

My script:
image

The error:


LocalPurchaseHandler line 39 (local script):

1 Like

The error message indicates that the Players:GetUserIdFromNameAsync function has failed because it encountered an unknown user. This might be because the name you’re passing to the function is not a valid player name, or it might be because the player has left the game before the function was called.

To fix this, you might want to add some error handling to your code to check if the player name is valid before calling the Players:GetUserIdFromNameAsync function. You could also add some error handling to check if the player is still in the game before calling this function.

Yeah but here is the main problem that I don’t even use Players:GetUserIdFromNameAsync function anywhere.
image

Why you put string.sub? data.Key is the UserId?

Can you print data.key to see what is the result?

It’s kinda not my script so honestly I don’t know, but here is the data.key:
image

-1 is not a valid userid in roblox :skull:

Can you see the script that set the key? Because it’s not the script that you see to us.
Is the UserId

I aplogize if this isn’t the script part what you asked for. I’m new to saving data.
image

image
(this is the same script which receives the remotefunction)

Fixed one ( i don’t know if this works, but test it):

local index = "Player_"..tostring(player.UserId)
1 Like

No, unfortunately it does not work. The error is the same and the data.key is also the same.

Can you test this possible solution:

local pages = amountStore:GetSortedAsync(false,10)
local currentPage = pages.GetCurrentPage()
local playerTable = {}
local amountTable = {}
for place,data in ipairs(currentPage) do
   table.insert(playerTable, #playerTable+1, Player:GetNameFromUserIdAsync(data.key)
   table.insert(amountTable, #amountTable+1, data.value)
end

And the other line:

local index = player.UserId
1 Like

You had a few mistakes there, but after fixing the following error pop up:

Can you send all of your script named “LocalPurchaseHandler”.

Here is the script (I removed the unnecessary things)

local Players = game:GetService("Players")
local remotes =  game:GetService("ReplicatedStorage"):WaitForChild("remote")

function updateDonations()
	local playerTable, amountTable = remotes:WaitForChild("retrieveInfo"):InvokeServer()
	for index, currentPlayer in pairs (playerTable) do
		leaderHolder:WaitForChild("Cell" .. tostring(index)):WaitForChild("Main"):WaitForChild("Username").Text = currentPlayer
		leaderHolder:WaitForChild("Cell" .. tostring(index)):WaitForChild("Main"):WaitForChild("Amount").Text = tostring(amountTable[index])
	end
end

updateDonations()

What 39 line is it related for?

It’s for requesting the Data, but i already mentioned it at the top.

local playerTable, amountTable = remotes:WaitForChild("retrieveInfo"):InvokeServer()

Can you show just the part of OnInvokeServer?

The script get playerTable, amountTable but after he set to {}??

local Players = game:GetService("Players")
local remotes =  game:GetService("ReplicatedStorage"):WaitForChild("remote")

function updateDonations()
	local playerTable, amountTable = remotes:WaitForChild("retrieveInfo"):InvokeServer()
	for index, currentPlayer in pairs (playerTable) do
		leaderHolder:WaitForChild("Cell" .. tostring(index)):WaitForChild("Main"):WaitForChild("Username").Text = currentPlayer
		leaderHolder:WaitForChild("Cell" .. tostring(index)):WaitForChild("Main"):WaitForChild("Amount").Text = tostring(amountTable[index])
	end
	local playerTable = {}
	local amountTable = {}
	for place,data in ipairs(currentPage) do
		table.insert(playerTable, #playerTable+1, Player:GetNameFromUserIdAsync(data.key)
			table.insert(amountTable, #amountTable+1, data.value)
	end

end

updateDonations()

You mixed up the local script and the server script
localPurchasehandler:

function updateDonations()
	local playerTable, amountTable = remotes:WaitForChild("retrieveInfo"):InvokeServer()
	for index, currentPlayer in pairs (playerTable) do
		leaderHolder:WaitForChild("Cell" .. tostring(index)):WaitForChild("Main"):WaitForChild("Username").Text = currentPlayer
		leaderHolder:WaitForChild("Cell" .. tostring(index)):WaitForChild("Main"):WaitForChild("Amount").Text = tostring(amountTable[index])
	end
end

Purchasehandler(server):

function retrieveInfo()
	local pages = amountStore:GetSortedAsync(false,10)
	local currentPage = pages:GetCurrentPage()
	local playerTable = {}
	local amountTable = {}
	for place,data in ipairs(currentPage) do
		table.insert(playerTable, #playerTable+1, Players:GetNameFromUserIdAsync(data.key))
		table.insert(amountTable, #amountTable+1, data.value)
	end
end