I am trying to make a chat tag script using the new TextChatService for my game: Noob Minigames. I made this script using the Roblox Documentation site and edited it to work with my game. I have no idea why, but my script wonβt work, and I have been trying to figure it out for days so I decided to post this to see if anyone could help. (P.S This is my first ever post asking for help.)
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
TextChatService.OnIncomingMessage = function(message: TextChatMessage)
local properties = Instance.new("TextChatMessageProperties")
local OwnerPlayerId = 792651524
local TesterPlayerId = 905724063
local BugFinderPlayerId = 216745876
local ArtistPlayerId = 423038282
local ThinkerPlayerId = 701646147
local BuilderPlayerId = 1667911408
local BugFinder2PlayerId = 1699249602
local Builder2PlayerId = 593063138
local GroupId = 9477217
if message.TextSource then
local player = Players:GetPlayerByUserId(message.TextSource.UserId)
if player:IsInGroup(GroupId) then
local Role = player:GetRoleInGroup(GroupId)
if Role == "Guest" then
properties.PrefixText = message.PrefixText
elseif Role == "BigHead" then
properties.PrefixText = "<font color='#00ffff'>[Fan]</font> " .. message.PrefixText
elseif Role == "BiggerHead" then
properties.PrefixText = "<font color='#ff0000'>[Superfan]</font> " .. message.PrefixText
elseif Role == "Moderator" then
properties.PrefixText = "<font color='#ffff00'>[Moderator]</font> " .. message.PrefixText
end
end
if player.UserId == OwnerPlayerId then
properties.PrefixText = "<font color='#ffaa00'>[π Owner π]</font> " .. message.PrefixText
elseif player.UserId == TesterPlayerId then
properties.PrefixText = "<font color='#ffaaff'>[π Tester π]</font> " .. message.PrefixText
elseif player.UserId == BugFinderPlayerId then
properties.PrefixText = "<font color='#55aa00'>[π Bug Finder π]</font> " .. message.PrefixText
elseif player.UserId == ArtistPlayerId then
properties.PrefixText = "<font color='#00aaff'>[π¨ Artist π¨]</font> " .. message.PrefixText
elseif player.UserId == ThinkerPlayerId then
properties.PrefixText = "<font color='#00aaff'>[π€ Thinker π€]</font> " .. message.PrefixText
elseif player.UserId == BuilderPlayerId then
properties.PrefixText = "<font color='#b19cd9'>[π¨ Builder π¨]</font> " .. message.PrefixText
elseif player.UserId == BugFinder2PlayerId then
properties.PrefixText = "<font color='#55aa00'>[π¦ Bug Finder π¦]</font> " .. message.PrefixText
elseif player.UserId == Builder2PlayerId then
properties.PrefixText = "<font color='#ff0000'>[π§ Builder π§]</font> " .. message.PrefixText
end
end
return properties
end
I placed this LocalScript in StarterPlayer>StarterPlayerScripts and it wouldnβt work as well as ServerScriptService.
I may be incorrect but does the chat service only work in server scripts? I may be wrong because I have not used the chat service recently but I swear I remember something like that.
The original script seemed to work for me, but I would recommend against fetching for group membership information as often as this. What you can do is when a player joins your game, you can fetch for their group membership information once and store it as an attribute of that player. That allows your chat callback and anything else in your game to reference this information at a moments notice.
You can do this by creating a Script in ServerScriptService:
local Players = game:GetService("Players")
local GROUP_ID = 9477217
Players.PlayerAdded:Connect(function(player)
local isInGroup = player:IsInGroup(GROUP_ID)
player:SetAttribute("isInGroup", isInGroup)
if isInGroup then
local groupRole = player:GetRoleInGroup(GROUP_ID)
if groupRole then
player:SetAttribute("groupRole", groupRole)
end
end
end)
This has the extra benefit of giving you a little more information about whats going on in the Studio properties window when you select a Player:
Then you can modify your original LocalScript in StarterPlayerScripts:
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
TextChatService.OnIncomingMessage = function(message: TextChatMessage)
local properties = Instance.new("TextChatMessageProperties")
local OwnerPlayerId = 792651524
local TesterPlayerId = 905724063
local BugFinderPlayerId = 216745876
local ArtistPlayerId = 423038282
local ThinkerPlayerId = 701646147
local BuilderPlayerId = 1667911408
local BugFinder2PlayerId = 1699249602
local Builder2PlayerId = 593063138
if message.TextSource then
local player = Players:GetPlayerByUserId(message.TextSource.UserId)
if player:GetAttribute("isInGroup") then
local Role = player:GetAttribute("groupRole")
if Role == "Guest" then
properties.PrefixText = message.PrefixText
elseif Role == "BigHead" then
properties.PrefixText = "<font color='#00ffff'>[Fan]</font> " .. message.PrefixText
elseif Role == "BiggerHead" then
properties.PrefixText = "<font color='#ff0000'>[Superfan]</font> " .. message.PrefixText
elseif Role == "Moderator" then
properties.PrefixText = "<font color='#ffff00'>[Moderator]</font> " .. message.PrefixText
end
end
if player.UserId == OwnerPlayerId then
properties.PrefixText = "<font color='#ffaa00'>[π Owner π]</font> " .. message.PrefixText
elseif player.UserId == TesterPlayerId then
properties.PrefixText = "<font color='#ffaaff'>[π Tester π]</font> " .. message.PrefixText
elseif player.UserId == BugFinderPlayerId then
properties.PrefixText = "<font color='#55aa00'>[π Bug Finder π]</font> " .. message.PrefixText
elseif player.UserId == ArtistPlayerId then
properties.PrefixText = "<font color='#00aaff'>[π¨ Artist π¨]</font> " .. message.PrefixText
elseif player.UserId == ThinkerPlayerId then
properties.PrefixText = "<font color='#00aaff'>[π€ Thinker π€]</font> " .. message.PrefixText
elseif player.UserId == BuilderPlayerId then
properties.PrefixText = "<font color='#b19cd9'>[π¨ Builder π¨]</font> " .. message.PrefixText
elseif player.UserId == BugFinder2PlayerId then
properties.PrefixText = "<font color='#55aa00'>[π¦ Bug Finder π¦]</font> " .. message.PrefixText
elseif player.UserId == Builder2PlayerId then
properties.PrefixText = "<font color='#ff0000'>[π§ Builder π§]</font> " .. message.PrefixText
end
end
return properties
end
Does this end up working any better for you? Iβm wondering if the fetching of membership data is happening too slowly doing it last-minute the other way.