Este ejemplo muestra cómo asignar etiquetas de chat a los jugadores en función de su membresía en un grupo.Las etiquetas de chat son una manera de identificar visualmente a un jugador en la ventana de chat y útil para indicar el rol o el estado de un jugador.

Debido a que las llamadas de chat de texto no ceden esperan una devolución de llamadano cesante, intentando consultar el estado de membresía del grupo de un jugador en la llamada de devolución TextChatService.OnIncomingMessage no se recomienda, ya que puede causar que el sistema de chat se bloquee o se vuelva irresponsable.
En cambio, establece un atributo de jugador cuando se unan al servidor.Establecer un atributo te permite reutilizar el estado del jugador en otras partes de tu experiencia, como permitir el acceso a áreas particulares o proporcionar experiencia de bonificación.
Crea un Script en ServerScriptService y agrega el siguiente código a él:
Servidorlocal Players = game:GetService("Players")-- Reemplazar 123456 con el ID de grupo que desea verificarlocal groupID = 123456Players.PlayerAdded:Connect(function(player)local success, isInGroup = pcall(function()return player:IsInGroup(groupID)end)if success and isInGroup thenplayer:SetAttribute("IsVIP", true)elseplayer:SetAttribute("IsVIP", false)endend)Crea un LocalScript en StarterPlayer ⟩ StarterCharacterScripts y agrega el siguiente código para mostrar una etiqueta [VIP] en la ventana de chat:
Clientelocal Players = game:GetService("Players")local TextChatService = game:GetService("TextChatService")TextChatService.OnIncomingMessage = function(message: TextChatMessage)local textSource = message.TextSourceif textSource thenlocal player = Players:GetPlayerByUserId(textSource.UserId)if player thenif player:GetAttribute("IsVIP") == true thenlocal overrideProperties = Instance.new("TextChatMessageProperties")overrideProperties.PrefixText = "[VIP] " .. message.PrefixTextreturn overridePropertiesendendendreturn nilend