How to change speaker chat tag when a value is changed?

Alright guys I need some help as you may know I am a youtuber that teaches people to make roblox games. My most popular series is “How To Make A Game Like Super Power Training Simulator”. In the game you gain and lose reputation when you kill players, I already have that but what I need help with is making the tag (in the chat) that says their Status change when their Status stat changes.

Any help will be very appreciated!

Current Code:

local Players = game:GetService('Players')
local ServerScriptService = game:GetService('ServerScriptService')

local ChatService = require(ServerScriptService:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))

ChatService.SpeakerAdded:Connect(function(PlayerName)
	local tagText = Players[PlayerName]:WaitForChild("leaderstats"):WaitForChild("Status")
	local color = nil
	if tagText.Value == "Innocent" then
		color = Color3.fromRGB(255,255,255)
	elseif tagText.Value == "Outlaw" then
		color = Color3.fromRGB(189, 83, 83)
	elseif tagText.Value == "Supervillan" then
		color = Color3.fromRGB(194, 0, 0)
	elseif tagText.Value == "Savior" then
		color = Color3.fromRGB(0, 191, 255)
	elseif tagText.Value == "Superhero" then
		color = Color3.fromRGB(0, 100, 255)
	end
	local Speaker = ChatService:GetSpeaker(PlayerName)
	Speaker:SetExtraData('NameColor', color)
	Speaker:SetExtraData('Tags', {{TagText = tagText.Value, TagColor = color}})
end)

Just add a .Changed event or the :GetPropertyChangedSignal method inside of the SpeakerAdded event.

local function updateTag(tagText, speakerName)
    local color = nil
	if tagText.Value == "Innocent" then
		color = Color3.fromRGB(255,255,255)
	elseif tagText.Value == "Outlaw" then
		color = Color3.fromRGB(189, 83, 83)
	elseif tagText.Value == "Supervillan" then
		color = Color3.fromRGB(194, 0, 0)
	elseif tagText.Value == "Savior" then
		color = Color3.fromRGB(0, 191, 255)
	elseif tagText.Value == "Superhero" then
		color = Color3.fromRGB(0, 100, 255)
	end
	local Speaker = ChatService:GetSpeaker(speakerName)
	Speaker:SetExtraData('NameColor', color)
	Speaker:SetExtraData('Tags', {{TagText = tagText.Value, TagColor = color}})
end

ChatService.SpeakerAdded:Connect(function(playerName)
	local tagText = Players[PlayerName]:WaitForChild("leaderstats"):WaitForChild("Status")
	updateTag(tagText, playerName) -- initialize when speaker is added
    tagText:GetPropertyChangedSignal('Value'):Connect(function() -- you can also use .Changed instead of :GetPropertyChangedSignal
        updateTag(tagText, playerName)
    end)
end)
1 Like

Thanks lol. The one place I didn’t try putting the changed event. Im new with the chat as you can tell. I can’t believe that I forgot to try it in there I swear I did. I guess I have bad memory.

2 Likes