I don’t understand where the issue is, the code is identical to how it was before, maybe roblox is trying to get user id from name, rather than name from user id, may someone help me?
while true do
task.wait(7)
local success, pages = pcall(function()
return data:GetSortedAsync(false, 10)
end)
if success then
local entries = pages:GetCurrentPage()
for rank, entry in pairs(entries) do
local cloneditem = item:Clone()
local username = game.Players:GetNameFromUserIdAsync(entry.key)
if playerContainer:FindFirstChild(username) then
playerContainer:FindFirstChild(username):Destroy()
end
if username then
cloneditem.Name = username
cloneditem.NameText.Text = username
end
cloneditem.RankText.Text = rank
cloneditem.CashText.Text = entry.value
cloneditem.Parent = playerContainer
print("yeah")
end
end
end
Roblox is pointing to this line in error
local username = game.Players:GetNameFromUserIdAsync(entry.key)
Sorry I did copied the wrong disabled script before, here’s the new one
local DataStoreService = game:GetService("DataStoreService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local data = DataStoreService:GetOrderedDataStore("data")
--local data = DataStoreService:GetDataStore("data")
local sessiondata = {}
local item = workspace.Leaderboard:WaitForChild("Item")
local playerContainer = workspace.Leaderboard.Leaderboard.LeaderboardGui.LeaderboardContainer.PlayersContainer
function playerAdded(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local dollars = Instance.new("IntValue")
dollars.Name = "Kills"
dollars.Parent = leaderstats
repeat
local success, PlayerData = pcall(function()
return data:GetAsync(plr.UserId, sessiondata[plr.UserId])
end)
local attempt = 1
attempt += 1
if not success then
warn(PlayerData)
task.wait(3)
end
until
success or attempt == 5
if success then
print("yay connected")
if not PlayerData then
print("Assigning default data")
PlayerData = {
["Kills"] = 0
}
end
sessiondata[plr.UserId] = PlayerData
else
warn("That's bad I guess")
plr:Kick("Unable to load your data. Try again later!!!!!!!!!")
end
dollars.Value = sessiondata[plr.UserId].Kills
dollars.Changed:Connect(function()
sessiondata[plr.UserId].Kills = dollars.Value
end)
leaderstats.Parent = plr
end
Players.PlayerAdded:Connect(playerAdded)
function playerRemoving(plr)
if sessiondata[plr.UserId] then
local success = nil
local Msg = nil
local attempt = 1
repeat
success, Msg = pcall(function()
data:SetAsync(plr.UserId, sessiondata[plr.UserId].Kills)
end)
attempt += 1
if not success then
warn(Msg)
task.wait(3)
end
until
success or attempt == 5
if success then
print("yay saving data!")
else
warn("Unable to save")
end
end
end
Players.PlayerRemoving:Connect(playerRemoving)
function serverShut()
if RunService:IsStudio() then
return
end
print("Sever has been shut down")
for i, player in ipairs(Players:GetPlayers()) do
task.spawn(function()
playerRemoving(player)
end)
end
end
game:BindToClose(serverShut)
while true do
task.wait(5)
local success, errorMsg = pcall(function()
return data:GetSortedAsync(false, 10)
end)
if success then
local pages = data:GetSortedAsync(false, 10)
local entries = pages:GetCurrentPage()
for rank, entry in pairs(entries) do
local cloneditem = item:Clone()
local username = game.Players:GetNameFromUserIdAsync(entry.key)
if playerContainer:FindFirstChild(username) then
playerContainer:FindFirstChild(username):Destroy()
end
if username then
cloneditem.Name = username
cloneditem.NameText.Text = username
end
cloneditem.RankText.Text = rank
cloneditem.CashText.Text = entry.value
cloneditem.Parent = playerContainer
print("yeah")
end
end
end
It’s used when you test with multiple players on the server like playtest but server it clone your character and gives an user id with -1 -2 etc also names player1 player2 etc but getNameFromUserIdAsync() things doesn’t work here cuz it’s not an actual player in the database
It’s actually used when an player isn’t in the game but when a player joins you can get an player instance
Yeah I get that part but I am just saying that I never knew that Player1 and Player2 had unique userids. I just thought they had the same ids as the one testing them.