Загрузка...

Как сделать теги к нику в чате?

Тема в разделе Roblox Studio создана пользователем Nikvet 7 июн 2025 в 13:11. 67 просмотров

Загрузка...
  1. Nikvet
    Nikvet Автор темы 7 июн 2025 в 13:11 0 Четверг
    Сначала пытался разобраться сам - не получилось, прибег к помощи ии ассистента в роблокс студио, он выдал такой код:

    local chatService = require(game.ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
    local service = game:GetService("MarketplaceService")

    local tags = {

    }

    chatService.SpeakerAdded:Connect(function(playerName)
    local speaker = chatService:GetSpeaker(playerName)
    local player = game.Players[playerName]

    if player and player.Team then
    local teamName = player.Team.Name
    local teamColor = player.Team.TeamColor.Color
    local teamTag = string.format("[%s] ", teamName)

    speaker:SetExtraData("NameColor", teamColor)
    speaker:SetExtraData("Tags", {{TagText = teamTag, TagColor = teamColor}})
    end
    end)


    Но он не работает. По задумке должен браться цвет и текст команды, в которой находится игрок, и писать её перед ником в чате.
    Пример: [Команда] Nikvet: сообщение
     
    7 июн 2025 в 13:11 Изменено
  2. Cactuz
    Cactuz 7 июн 2025 в 13:19 Лучший курс на TRX,Energy - https://lolz.live/threads/8610296/ 7718 5 июл 2019
    Используй TextChatMessageProperties
     
    1. Cactuz
      Скрипт сам переделаешь если нужно:
      Server-side:

      Код
      local Players = game:GetService("Players")
      local Teams = game:GetService("Teams")

      Players.PlayerAdded:Connect(function(player)
      local function updateTeamAttributes()
      if player.Team then
      player:SetAttribute("TeamName", player.Team.Name)
      else
      player:SetAttribute("TeamName", nil)
      end
      end

      updateTeamAttributes()
      player:GetPropertyChangedSignal("Team"):Connect(updateTeamAttributes)
      end)
      Local Script:

      Код
      local Players = game:GetService("Players")
      local TextChatService = game:GetService("TextChatService")

      TextChatService.OnIncomingMessage = function(message)
      local textSource = message.TextSource
      if not textSource then return nil end

      local player = Players:GetPlayerByUserId(textSource.UserId)
      if not player then return nil end

      local teamName = player:GetAttribute("TeamName")

      if teamName then
      local override = Instance.new("TextChatMessageProperties")
      override.PrefixText = "[" .. teamName .. "] " .. message.PrefixText
      return override
      end

      return nil
      end
    2. Nikvet Автор темы
      Cactuz, спасибо, всё работает.
Top