Another typo? Did you mean game.Workspace.GlobalLeaderboard?
You’re probably right, I usually make a separate datastore for everything because I’m overly complicating
Still didn’t fix it, however probably fixed another error somewhere along the lines.
I need to be more careful!
OK, just been reading through the developer pages on OrderedDataStores.
Here, try it just with:
local userName = data.key
print(userName)
See what it comes up with - if it doesn’t print anything at all, then something before the ipairs loop has gone wrong.
I’ve also got a feeling there’s something wrong with the ‘Rank’ part, which could relate to that Argument 1 missing/nil error. I’ll have a check through that.
Your theory was right, nothing printed.
Update: Still having issues, looked through my code and I cannot figure out why. Help is appreciated.
Is there Data in the Data store?
Yes. There is data of around 5 people.
Hmm try setting some different fake users using :SetAsync()
You can remove them later
OrderedDataStore:SetAsync("Jonny", 56)
OrderedDataStore:SetAsync("Mary", 68)
OrderedDataStore:SetAsync("John", 99)
tell me if it works
It doesn’t make a difference. Per the tutorial I used, it should work even with one person.
Sorry for being late
But im going to test your code to see if it works give me a moment
Well im getting this error
Argument 1 missing or nil
which leads to
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
The key is not the UserId of a player as when you set the Data of the player you have player.UserId … “-time” for GetNameFromUserIdAsync() to work it has to be a straight UserId without* anything else
local userName = Data.key
also make the D in Data lowercase it will error if not also you previously defined the name of the player on the leaderboard so this line of code is unnecessary
Besides these errors this is my output after fixing them
https://gyazo.com/839e87a0003dfa1af7154b72e1671629
I’ll try it tomorrow. Thank you!
So I made some changes, making the key only the UserId. Now, I get no errors, but it still doesn’t work. Here is my new code:
local DataStoreService = game:GetService("DataStoreService")
local WinsLeaderboard = DataStoreService:GetOrderedDataStore("timeDataStore".."-time")
local function updateLeaderboard()
local success, errorMessage = pcall(function()
local Data = WinsLeaderboard:GetSortedAsync(false, 5)
local WinsPage = Data:GetCurrentPage()
for Rank, data in ipairs(WinsPage) do
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = userName
local Time = data.value
local isOnLeaderboard = false
for i, v in pairs (game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()) do
if v.Player.Text == Name then
isOnLeaderboard = true
break
end
end
print(userName)
if Time and isOnLeaderboard == false then
local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
newLbFrame.Player.Text = Name
newLbFrame.Time.Text = Time
newLbFrame.Rank.Text = "#"..Rank
newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + .08 * #game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren(), 0)
newLbFrame.Parent = game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder
end
end
end)
end
while true do
for _, player in pairs (game.Players:GetPlayers()) do
WinsLeaderboard:SetAsync(player.UserId .. "-time", player.leaderstats.TimePlayed.Value)
end
for _, frame in pairs (game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()) do
frame:Destroy()
end
updateLeaderboard()
print("Updated Leaderboard")
wait(30)
end
Try running it without the pcall. This way, it will show you the error, rather than erring silently (if an error occurs in a pcall, it doesn’t do anything)
What error do you get if you do this?
Good idea, trying that quickly.
It may have something to do with this line:
Earlier, some one said to add this code:
This adds values to the stores with strings as their keys, not ints. When it runs, it tries to convert the string to an int but can’t because it’s only letter, so it returns nil (I think). Because of this, the get user from userid function will error because the first argument is nil.
If there is nothing else saved to the data store, you could try changing its name and adding this code:
OrderedDataStore:SetAsync("12344", 56)
OrderedDataStore:SetAsync("54321", 68)
OrderedDataStore:SetAsync("21357", 99)
(Those are just random numbers)