How to give top 5 leaderstat players a chat tag

I already am saving the leaderstats. I just need a way to check if a player holds the top 5 highest position, and to give that person a chattag.

Here

More

Even more

(Personally think the first one is best tho)

Anyways happy developing!

Not sure if you need the chat tag part but here
I would do something like this:

local Players = game:GetService("Players")
local ChatService = require(game.ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
Players.PlayerAdded:Connect(function(plr)
    ChatService.SpeakerAdded:Connect(function(player)
    local Speaker = ChatService:GetSpeaker(player)
    local Id = Players:GetUserIdFromNameAsync(player)
    local plr = Players:FindFirstChild(player)
    -- check if player is top 5
        Speaker:SetExtraData('Tags', {{TagText = "Top 5", TagColor = Color3.fromRGB(255, 0, 0)}})
end)
2 Likes

use this

local t1 = game.Players:GetChildren()
local t2 = {}
for i = 1, 5, 1 do
 local Higest = 0
 local Plr
 for i, v in pairs(t1) do
  if game.Players:FindFirstChild(v).leaderstats.Coins.Value > Higest then --replace "Coins" with your leaderstats value
   Higest = game.Players:FindFirstChild(v).leaderstats.Coins.Value
   plr = v
  end
 end
 table.Remove(t1, plr)
 table.Insert(t2, plr)
end

now t2 will have the list of top 5 players and you can use a function to create a tag for them like @JustCrock replied

or you can use this complete script

local t2 = {}
game.Players.PlayerAdded:Connect(function()
 table.Clear(t2)
 local t1 = game.Players.GetChildren()
 for i = 1, 5, 1 do
  local Higest = 0
  local Plr
  for i, v in pairs(t1) do
   if game.Players:FindFirstChild(v).leaderstats.Coins.Value > Higest then --replace "Coins" with your leaderstats value
    Higest = game.Players:FindFirstChild(v).leaderstats.Coins.Value
    plr = v
   end
  end
  table.Remove(t1, plr)
  table.Insert(t2, plr)
 end
end)


local Players = game:GetService("Players")
local ChatService = require(game.ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
Players.PlayerAdded:Connect(function(plr)
    ChatService.SpeakerAdded:Connect(function(player)
    local Speaker = ChatService:GetSpeaker(player)
    local Id = Players:GetUserIdFromNameAsync(player)
    local plr = Players:FindFirstChild(player)
    if table.Find(t2, plr) then
     Speaker:SetExtraData('Tags', {{TagText = "Top 5", TagColor = Color3.fromRGB(255, 0, 0)}})
    end
end)


I get this error

Have you created leaderstats and stuffs ?

yes

i need characters oooooof welp time to type