Bu örnek, oyunculara bir grup üyeliklerine dayalı olarak sohbet etiketleri atamanın nasıl yapılacağını göstermektedir. Sohbet etiketleri, sohbet penceresinde bir oyuncuyu görsel olarak tanımlamak için bir yol olup, bir oyuncunun rolünü veya durumunu belirtmek için faydalıdır.

Çünkü metin sohbet geri çağırmaları beklenmeyen bir geri çağırma beklediğinden, TextChatService.OnIncomingMessage geri çağırmasında bir oyuncunun grup üyelik durumunu sorgulamaya çalışmak önerilmez; bu durum sohbet sisteminin takılmasına veya yanıt veremez hale gelmesine neden olabilir.
Bunun yerine, bir oyuncu sunucuya katıldığında bir öznitelik ayarlayın. Bir öznitelik ayarlamak, oyuncunun durumunu oyununuzun diğer bölümlerinde tekrar kullanmanıza olanak tanır, örneğin belirli alanlara erişim sağlamak veya bonus deneyimler sunmak için.
ServerScriptService içinde bir Script oluşturun ve aşağıdaki kodu ekleyin:
Sunuculocal Players = game:GetService("Players")-- Kontrol etmek istediğiniz grup ID'si ile 123456'yı değiştirinlocal groupID = 123456Players.PlayerAdded:Connect(function(player)local success, isInGroup = pcall(function()return player:IsInGroupAsync(groupID)end)if success and isInGroup thenplayer:SetAttribute("IsVIP", true)elseplayer:SetAttribute("IsVIP", false)endend)StarterPlayer ⟩ StarterCharacterScripts içinde bir LocalScript oluşturun ve sohbet penceresinde [VIP] etiketini göstermek için aşağıdaki kodu ekleyin:
İstemcilocal 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