Questo esempio mostra come assegnare etichette di chat ai giocatori in base alla loro adesione a un gruppo.Le etichette di chat sono un modo per identificare visivamente un giocatore nella finestra di chat e utile per indicare il ruolo o lo Statodi un Giocatore.

Poiché le chiamate di chat di testo non cedenti si aspettano una chiamata non cedente, tentando di interrogare lo stato di appartenenza al gruppo di un giocatore nel RichiamaTextChatService.OnIncomingMessage non è raccomandato, poiché può causare il blocco del sistema di chat o diventare irrispondente.
Invece, imposta un attributo player quando si uniscono al Server.Impostare un attributo ti consente di riutilizzare lo stato del Giocatorein altre parti della tua esperienza, come consentire l'accesso a aree particolari o fornire esperienza bonus.
Crea un Script in ServerScriptService e aggiungi il seguente codice ad esso:
Serverlocal Players = game:GetService("Players")-- Sostituisci 123456 con l'ID del gruppo che vuoi controllarelocal 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 in StarterPlayer ⟩ StarterCharacterScripts e aggiungi il seguente codice per visualizzare un tag [VIP] nella finestra di 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