I want a chat tag that shows something like this, #100 (The data is from leaderstats, kills)
Tried to do the code but cant figure the rest out
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
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!
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
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
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
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