Hey, so I am currently doing a Global Leaderboard system for my simulator and I just ran into a problem. I am trying to get the UserId form the top 3 players and then does userId’s to get the clothing and hats the only problem I have is, how do I get the UserId from an OrderedDataStore?
Here is the Script:
local TotalWheatODS = game:GetService("DataStoreService"):GetOrderedDataStore("TotalCash1")
local function Handler()
local Success, Err = pcall(function()
local Data = TotalWheatODS:GetSortedAsync(false, 100)
local TotalWheatPage = Data:GetCurrentPage()
for Rank, Data in ipairs(TotalWheatPage) do
local Name = Data.key
local TotalWheat = Data.value
local NewObj = game.ReplicatedStorage:WaitForChild("lbFrame"):Clone()
NewObj.Player.Text = Name
NewObj.TotalWheat.Text = TotalWheat
NewObj.Rank.Text = "#"..Rank
NewObj.Position = UDim2.new(0, 0, NewObj.Position.Y.Scale + (0.08 * #game.Workspace.StatCoinBoard.lbGUI.Holder:GetChildren()), 0)
NewObj.Parent = game.Workspace.StatCoinBoard.lbGUI.Holder
end
end)
if not Success then
error(Err)
end
end
while true do
for _,Player in pairs(game.Players:GetPlayers()) do
TotalWheatODS:SetAsync(Player.Name, Player.Totalcash.Value)
end
for _,v in pairs(game.Workspace.StatCoinBoard.lbGUI.Holder:GetChildren()) do
if v.Name == "lbFrame" then
wait()
v:Destroy()
end
end
Handler()
wait(250)
end
I tried looking in the developer API references but found nothing
You should be saving the UserId as the key for if a player changes their username. But there are functions you could use to get the UserId from the Name and the Name from the UserId.
@iiNemo is very correct that you should be using the UserId as the player’s key. By using a username as the key, a player could lose all their data if they do a name change.
In your case, since you are using an OrderedDataStore, the player’s data will not be erased( Unless you are getting player data from it ), but will instead become a new key. This means if the player changes their username, they will have two separate places on the leaderboard for each of their usernames.