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.
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.
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
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()
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