I wanted to make chat tags the screen the global leaderboard rank in chat but it ended up not working and breaking the global leaderboard!
local DataStoreService = game:GetService("DataStoreService")
local DeathsLeaderboard = DataStoreService:GetOrderedDataStore("DeathsLeaderboard")
local ChatService = game:GetService("Chat")
local function updateLeaderboard()
local success, errorMessage = pcall(function()
local Data = DeathsLeaderboard:GetSortedAsync(false, 100)
local DeathsPage = Data:GetCurrentPage()
for Rank, data in ipairs(DeathsPage) do
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = userName
local Deaths = data.value
local isOnLB = false
for i, v in pairs(game.Workspace.Lobby.Leaderboards.Leaderboard_Deaths.DeathLeaderboard.SurfaceGui.Holder:GetChildren()) do
if v.Player.Text == Name then
isOnLB = true
break
end
end
if Deaths and isOnLB == false then
local newLBFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrameDeaths"):Clone()
newLBFrame.Player.Text = Name
newLBFrame.Deaths.Text = Deaths
newLBFrame.Rank.Text = "#"..Rank
newLBFrame.Position = UDim2.new(0, 0, newLBFrame.Position.Y.Scale + (.1 * #game.Workspace.Lobby.Leaderboards.Leaderboard_Deaths.DeathLeaderboard.SurfaceGui.Holder:GetChildren()), 0)
newLBFrame.Parent = game.Workspace.Lobby.Leaderboards.Leaderboard_Deaths.DeathLeaderboard.SurfaceGui.Holder
local player = game.Players:FindFirstChild(Name)
if player then
ChatService:AddPlayerTagList({
player = player,
tagText = "💀#" .. Rank,
tagColor = Color3.new(1, 0, 0), -- You can customize the color
})
end
end
end
end)
if not success then
print(errorMessage)
end
end
while true do
for _, player in pairs(game.Players:GetPlayers()) do
DeathsLeaderboard:SetAsync(player.UserId, player.leaderstats.Deaths.Value)
end
for _, frame in pairs(game.Workspace.Lobby.Leaderboards.Leaderboard_Deaths.DeathLeaderboard.SurfaceGui.Holder:GetChildren()) do
frame:Destroy()
end
updateLeaderboard()
print("Updated!")
wait(60)
end
It would be nice if i could get a solution instantly instead of getting it explained bc i need it faast!