Hello! I’m having issues with this code of where there is no errors but it doesn’t work with any more than one player. GUI is a part in my GlobalLeaderboard model by the way.
It’s a leaderboard system.
local DataStoreService = game:GetService("DataStoreService")
local MissionsLeaderboard = DataStoreService:GetOrderedDataStore("MissionsLeaderboard")
local function updateLeaderboard()
local success, errormessage = pcall(function()
local Data = MissionsLeaderboard:GetSortedAsync(false, 3)
local MissionsPage = Data:GetCurrentPage()
for Rank, data in ipairs(MissionsPage) do
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = userName
local Missions = data.Value
local isOnLeaderboard = false
for i, v in pairs(game.Workspace.GlobalLeaderboard.GUI.SurfaceGui.Holder:GetChildren()) do
if v.Player.Text == Name then
isOnLeaderboard = true
break
end
end
print("huh, interesting")
if isOnLeaderboard == false then
print("Whoop")
local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
newLbFrame.Player.Text = Name
newLbFrame.Missions.Text = game.Players:WaitForChild(Name).leaderstats.Missions.Value
newLbFrame.Rank.Text = "#"..Rank
newLbFrame.Position = UDim2.new(0,0, newLbFrame.Position.Y.Scale + (0.2 * #game.Workspace.GlobalLeaderboard.GUI.SurfaceGui.Holder:GetChildren()))
newLbFrame.Parent = game.Workspace.GlobalLeaderboard.GUI.SurfaceGui.Holder
print("so that worked")
end
end
end)
if not success then
print(errormessage)
end
end
while true do
for _, player in pairs(game.Players:GetPlayers()) do
MissionsLeaderboard:SetAsync(player.UserId, player.leaderstats.Missions.Value)
end
for _, frame in pairs(game.Workspace.GlobalLeaderboard.GUI.SurfaceGui.Holder:GetChildren()) do
frame:Destroy()
end
updateLeaderboard()
print("Updated Leaderboard!")
task.wait(10)
end
Thanks for your help!