Hi There!!
Today I have been working on a Global Leaderboard. I am still learning to develop, so I watched this video:
https://www.youtube.com/watch?v=sXpuGnVzsxw
When I finished, I got this error:
I watched the video to see if he got the error, but he did not so I came here.
My script:
local DataStoreService = game:GetService("DataStoreService")
local WinsLeaderboard = DataStoreService:GetOrderedDataStore("WinsLeaderboard")
local function updateLeaderboard()
local succes, errorMessage = pcall(function()
local Data = WinsLeaderboard:GetSortedAsync(false, 5)
local WinsPage = Data:GetCurrentPage()
for rank, data in ipairs(WinsPage) do
local userName = game.GetPlayers:GetNameFromUserIdAsync(tonumber(data.key))
local name = userName
local Wins = 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
if Wins and isOnLeaderboard == false then
local newLeaderboardFrame = game.ReplicatedStorage:WaitForChild("LeaderBoardFrame"):Clone()
newLeaderboardFrame.Player.Text = Name
newLeaderboardFrame.Wins.Text = Wins
newLeaderboardFrame.Rank.Text = "#"..Rank
newLeaderboardFrame.Position = UDim2.new(0, 0, newLeaderboardFrame.Position.Y.Scale + (.08 * #game.Workspace.GlobalLeaderBoard.LeaderBoardGUI.Holder:GetChildren()), 0)
newLeaderboardFrame.Parent = game.Workspace.GlobalLeaderBoard.LeaderBoardGUI.Holder
end
end
end)
if not succes then
print(errorMessage)
end
end
while true do
for _, player in pairs(game.Players:GetPlayers()) do
WinsLeaderboard:SetAsync(player.UserId, player.leaderstats.Wins.Value)
end
for _, frame in pairs(game.Workspace.GlobalLeaderBoard.LeaderBoardGUI.Holder:GetChildren()) do
frame:Destroy()
end
updateLeaderboard()
print("Updated!")
wait(10)
end
If you want any more details, just tell me and I will post back!!
hope you can help!!