Chat Tags issue

I’m trying to fix an issue with my chat tags, they should show the country’s name before their username, however instead it just shows “Label” (user’s name)

local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local chat = game:GetService("Chat")
local Players = game:GetService("Players")

while not ChatService do wait() end

local tagcolor = require(game.ReplicatedStorage.TagColors)
local countries = tagcolor.countries

ChatService.SpeakerAdded:Connect(function(PlrName)
	local player = Players:FindFirstChild(PlrName)
	local label = game.StarterGui.Menus.Flag.CountryName
	if label and label:IsA("TextLabel") then
		local country = label.Text
		local color = Color3.new(0.12549, 0.329412, 0.454902)
		if color then
			local Speaker = ChatService:GetSpeaker(PlrName)
			Speaker:SetExtraData('Tags', {{TagText = country, TagColor = color}})
		end
	end
	

	player.Chatted:Connect(function(message)
		local speaker = ChatService:GetSpeaker(PlrName)
		local country = speaker:GetExtraData("Tags")[1].TagText
		message = "["..country.."] "..message
		chat:Chat(speaker, message)``` This is a server script in serverscriptservice

I think it might be because you’re getting the CountryName from StarterGui, and most likely you didn’t edit the text around there to be the default so it stays as Label

You could try getting it from player.PlayerGui, but most likely it may not work if you put text in CountryName via the client which is what most do, because the server will still see it as Label.

You might need a way to get someone’s country via the server to do what you require, such as storing in a value or in an attribute that the server can access

1 Like

I did something similar to this, i made a string value and i set the value of the string to “France” but now it just appears as [] heres the current script

local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local chat = game:GetService("Chat")
local Players = game:GetService("Players")


while not ChatService do wait() end

local tagcolor = require(game.ReplicatedStorage.TagColors)
local countries = tagcolor.countries
local repstorage = game.ReplicatedStorage
local countryy = repstorage.Country.Value
ChatService.SpeakerAdded:Connect(function(PlrName)
	local player = Players:FindFirstChild(PlrName)
	local label = game.StarterGui.Menus.Flag.CountryName
	if label and label:IsA("TextLabel") then
		local country = countryy
		local color = Color3.new(0.12549, 0.329412, 0.454902)
		if color then
			local Speaker = ChatService:GetSpeaker(PlrName)
			Speaker:SetExtraData('Tags', {{TagText = country, TagColor = color}})
		

		end
	end
	player.Chatted:Connect(function(message)
		local speaker = ChatService:GetSpeaker(PlrName)
		local country = speaker:GetExtraData("Tags")[1].TagText
		message = "["..country.."] "..message
		chat:Chat(speaker, message)
	end)
end)

Means that your Country value is empty, I would recommend having a country value for each player if each player has their own separate country rather than a global country. You could make Attributes or StringValues and put them in each player and set them accordingly, then when it needs to get it, you just set that value

Though another issue arises as it may make the tag before the country, so you’d have to wait for the Value to change before making a tag

I went ahead and tested it out but the country value was set to france when i typed out the message, and it still was empty

Then most likely it’s because it’s making the tag way too early, Maybe you can put a Value.Changed event inside of the speakerAdded so when the value of the Country changes, it creates the tag, Value being the Country value

countryy.Changed:Connect(function(value)
	countryy.Value = value
end)

so something like this?

Example from the roblox dev wiki

value.Changed:Connect(function(NewValue)

	print(NewValue) -- NewValue in your case would be the country, so you set that as the tag

end)

Checked your edit, yes you do need the changed event, but inside of that changed event is where you use your SetExtraData line since you need to make the tag there, using NewValue as your country

So I’d put this line local Speaker = ChatService:GetSpeaker(PlrName) Speaker:SetExtraData('Tags', {{TagText = country, TagColor = color}})
Under the value.changed?

Yes, making sure that country is named the same as the parameter