Chat tag for leaderstats

  1. I want a chat tag that shows something like this, #100 (The data is from leaderstats, kills)

  2. Tried to do the code but cant figure the rest out

  3. No solution found

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function()
		local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
		local speaker = ChatService:GetSpeaker(player.Name)
		
		if player <= 100 and player ~= 0 then
			local text = "🏆 #" .. tostring(player)

			speaker:SetExtraData("Tags", {{TagText = text, TagColor = Color3.fromRGB(0, 234, 255)}})
		end
	end)
end)

Having trouble with trying to contact leaderstats (kills)

if player <= 100 and player ~= 0 then
is just seeing if the player (an object value) is less than / not equal to an integer value, which means that no matter what, it won’t fire.

You may have to put all players into a table, then sort said table by kills. From there, you can get there index in the table (table.find(Table, Player)) and use that for the tag

How do I get the script to find the kills?

If you already created the leaderstats values in an another script(kills, deaths, etc), then you would get the kills by player.leaderstats.Kills. Exactly like this:

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function()
		local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
                 local Kills = player.leaderstats:WaitForChild("Kills") -- you can replace leaderstats to the folder that the kills object is in. 
		local speaker = ChatService:GetSpeaker(player.Name)
		
		if Kills  and Kills.Value <= 100 and player ~= 0 then
			local text = "🏆 #" .. tostring(player)

			speaker:SetExtraData("Tags", {{TagText = text, TagColor = Color3.fromRGB(0, 234, 255)}})
		end
	end)
end)

Haven’t tested this yet, but tell me if there are any errors in the output. If you don’t understand something, tell me and I will be happy to answer you!

1 Like

Mhm, Nothing is working, And no errors in the output.

	player.Chatted:Connect(function()
		local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
		
		
		
		local Kills = player.leaderstats:WaitForChild("Kills") -- you can replace leaderstats to the folder that the kills object is in. 
		local speaker = ChatService:GetSpeaker(player.Name)

		if Kills  and Kills.Value <= 100 and Kills.Value ~= 0 then
			local text = "🏆 #" .. tostring(player)

			speaker:SetExtraData("Tags", {{TagText = text, TagColor = Color3.fromRGB(0, 234, 255)}})
		end
	end)
end)

This should work. In the past reply, I forgot to replace the player object that is compared to 0 to the kills value.

Still doesn’t work, The leaderstats is a child of the player, and the script here is put in workspace as a normal script. Im also getting (unknown global player) Upon fixing it by adding “game.Players.PlayerAdded:Connect(function(player)”

It still refuses to work, Even when tested out of game.

And when playing the real game random people with only 1 kill (Needs atleast 400-600 to get on leaderboard) This happens

Capture

like this?


when player has 400 kills or greater it add extra tag?

local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)

local function GetPlayersKills()
	local PlayersKills = {}
	for _, Player in pairs(game.Players:GetPlayers()) do
		local Kills = Player.leaderstats.Kills 
		PlayersKills[Player.Name] = Kills.Value
	end
	return PlayersKills
end

local function SetChatTag()
	for PlayerName, Kills in pairs(GetPlayersKills()) do
		if Kills >= 400 then
			local Speaker = ChatService:GetSpeaker(PlayerName)
			Speaker:SetExtraData(
				"Tags",
				{
					{TagText = "🏆 #"..Kills, TagColor = Color3.new(0, 234, 255)}
				}
			)
		end
	end
end

while wait(2) do -- Updates every 2 seconds
	if #game.Players:GetPlayers() >= 1 then
		pcall(SetChatTag)
	end
end	
1 Like

A bit like that. It should get the top 100 players ranked by kills e.g.

Joe #43
jeff #44

i still didnt test this cuz my pc couldnt handle multi client test

try

local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)

local function GetTopKills()
	local TopPlayers = {}
	for _, Player in pairs(game.Players:GetPlayers()) do
		local Kills = Player.leaderstats.Kills
		if Kills.Value >= 400 then
			table.insert(TopPlayers, tostring(Kills.Value).."_"..Player.Name)	
		end
	end
	table.sort(TopPlayers)
	for Index, Kills_PlayerName in pairs(TopPlayers) do
		local PlayerName = Kills_PlayerName:split("_")[2]
		TopPlayers[Index] = PlayerName
	end
	return TopPlayers
end

local function SetChatTag()
	for Rank, PlayerName in pairs(GetTopKills()) do
		local Speaker = ChatService:GetSpeaker(PlayerName)
		Speaker:SetExtraData(
			"Tags",
			{
				{TagText = "🏆 #"..Rank, TagColor = Color3.new(0, 234, 255)}
			}
		)
	end
end

while wait(3) do -- Updates every 3 seconds
	pcall(SetChatTag)
end

image

re1

re2

Doesn’t add up. (Glitched noob isn’t on the leaderboard at all)

What do you exactly want? Do you mean that you want the players to be listed into a leaderboard from the highest to the lowest?

1 Like

Yes but only a certain number (Like #100 to #1) So it doesn’t get to big (like #4354)

Also I think It does work (GlitchedNoob had some sort of kills error, I think he had around 1000 kills but was hidden)

I want it like globally, Instead of on a server, Lets say this:
Tim has the highest kills globally, With 3k kills
But he isnt on this server, Bill is. Bill has 500 kills

But bill is ranked #1 in the server?

And also
Tim = #1
whatever = #2
whatever = #3
whatever = #4
whatever = #5
bill = #6

Can you see bill should be ranked 6th in the world but is #1

1 Like

Have you fixed your issue? If so, could you dm me at Jaski#0001 i have a few question(s) please

No I haven’t yet. I’ll message you now!

Edit: Its not working, Did you type it wrong, My discord is TimLockWood#0245.

Added you! its in the sky

jesus i hate the 30 letters thingy its annoying

1 Like