I’ve attempted to retrieve a Players username from a data store but can’t seem to be successful with it.
Here’s the code:
for position, v in ipairs(topPage) do
local UserId = v.key
print(v.key)
print(Players:GetPlayerByUserId(v.key))
local Username = tostring(Players:GetPlayerByUserId(UserId))
local function GetTopPlayers()
local data
local succes, err = pcall(function()
data = MainData:GetSortedAsync(Ascending, MaxItems, MinValue, MaxValue)
end)
if err then
warn("An error Occured, Couldn't get Top Players!")
print(err)
data = MainData:GetSortedAsync(Ascending, MaxItems, MinValue, MaxValue)
end
local topPage = data:GetCurrentPage()
for position, v in ipairs(topPage) do
local UserId = tonumber(v.key)
local Username = tostring(Players:GetPlayerByUserId(UserId))
local Item = Template:Clone()
Item.Name = "Place_"..tostring(position)
Item.Visible = true
Item.Parent = ScrollinFrame
Item.Frame.Place.Text = tostring(position)
Item.Frame.Value.Text = tostring(v.value)
Item.Frame.Username.Text = Username
end
end
while wait(UpdateTime * 60) do
for i, Player in pairs(Players:GetPlayers()) do
local leaderstats = Player:FindFirstChild("leaderstats")
print(Players:GetPlayerByUserId(Player.UserId))
if not leaderstats then
warn("Could not find leaderstats!")
break
end
local statsValue = leaderstats:FindFirstChild(StatsName)
if not statsValue then
warn("Could not find "..StatsName)
break
end
local succes, err = pcall(function()
MainData:UpdateAsync(tostring(Player.UserId), function()
return tonumber(statsValue.Value)
end)
end)
if err then
warn("Could not Save data!")
print(err)
MainData:UpdateAsync(tostring(Player.UserId), function()
return tonumber(statsValue.Value)
end)
end
end
for i, Frame in pairs(ScrollinFrame:GetChildren()) do
if Frame:IsA("ImageLabel") then
Frame:Destroy()
end
end
GetTopPlayers()
end
The topPage might return nil
check the module or the code whatever you typed there you should always print values to check if they return what you need and not nil
I tried printing their usenames but they all returned nill, weirdly when i tried to manually get their Usernames by the userid i have printed it still has returned to nill.