Players cannot chat with TextChatService without a chat tag?

Recently I’ve noticed that when players are in my game, I can see chats with people who have a chat tag, but players who were not given one will make the chat sound but not be able to speak.

I have a feeling this is something to do with the chat tag script as I’ve used this from someone else.

local textChatService = game:GetService("TextChatService")
local players = game:GetService("Players")
local marketplaceService = game:GetService("MarketplaceService")

local vipGamepassId = 17347981

local ownerUserId = 382183363  -- Replace this with your id
local adminUserIds = {1055032964, 353620157}  -- Replace the ids with ur game admins
local modUserIds = {1320435220, 1056405017}  -- Replace the ids with ur game mods


local function isUserInList(userId, userList)
	for _, id in pairs(userList) do
		if userId == id then
			return true
		end
	end
	return false
end

textChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		local player = players:GetPlayerByUserId(message.TextSource.UserId)

		if player then
			
			if player.UserId == ownerUserId then
				properties.PrefixText = "<font color ='#42fd62'>[Owner]</font> " .. message.PrefixText
				
			elseif isUserInList(player.UserId, adminUserIds) then
				properties.PrefixText = "<font color ='#ffa245'>[Developer]</font> " .. message.PrefixText
				
			elseif isUserInList(player.UserId, modUserIds) then
				properties.PrefixText = "<font color ='#ff254d'>[Admin]</font> " .. message.PrefixText
				
			elseif marketplaceService:UserOwnsGamePassAsync(player.UserId, vipGamepassId) then
				properties.PrefixText = "<font color ='#23f4ff'>[Captain]</font> " .. message.PrefixText
			end
		end
	end

	return properties
end

Above is the script used to give players tags based on their rank in development or gamepass owned.
I would appreciate if anyone could help me fix players messages not popping up in chat aside from those with tags.

Unfortunately this removed the tags and did not fix the issue ^^;

Probably because you can’t use UserOwnsGamePassAsync for other clients, create a remote function, and use that to determine the prefix

1 Like

You must not yield inside the OnIncomingMessage callback. That means you can’t use UserOwnsGamePassAsync directly there.

Instead, you should get the user tags when the player joins, store them, and then just look up the tag instantly in OnIncomingMessage.

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")

local vipGamepassId = 17347981

local ownerUserId = 382183363
local adminUserIds = {1055032964, 353620157}
local modUserIds = {1320435220, 1056405017}

local playerTags = {}

local function isUserInList(userId, userList)
	for _, id in ipairs(userList) do
		if userId == id then
			return true
		end
	end
	return false
end

local function assignPlayerTag(player)
	local userId = player.UserId

	if userId == ownerUserId then
		playerTags[userId] = "<font color ='#42fd62'>[Owner]</font>"
	elseif isUserInList(userId, adminUserIds) then
		playerTags[userId] = "<font color ='#ffa245'>[Developer]</font>"
	elseif isUserInList(userId, modUserIds) then
		playerTags[userId] = "<font color ='#ff254d'>[Admin]</font>"
	else
		local success, ownsPass = pcall(function()
			return MarketplaceService:UserOwnsGamePassAsync(userId, vipGamepassId)
		end)
		if success and ownsPass then
			playerTags[userId] = "<font color ='#23f4ff'>[Captain]</font>"
		else
			playerTags[userId] = nil -- no tag
		end
	end
end

Players.PlayerAdded:Connect(function(player)
	assignPlayerTag(player)
end)

Players.PlayerRemoving:Connect(function(player)
	playerTags[player.UserId] = nil
end)

TextChatService.OnIncomingMessage = function(message: TextChatMessage)
	local props = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		local userId = message.TextSource.UserId
		local prefix = playerTags[userId]
		if prefix then
			props.PrefixText = prefix .. " " .. message.PrefixText
			return props
		end
	end

	return nil
end

1 Like

I see, i’m not very good with remotes and chat functions though as I mostly work with UI. This could work as a learning experience thoughh

Okay this fixed being able to chat with other users but the tags are still missing, I appreciate this tho!

Wrong

MarketPlace:UserOwnsGamePassAsync() can only query local player

You can yield, it will just delay the message

LocalScript inside StarterGui:

local TextChatService = game:GetService("TextChatService")

local ownerUserId = 382183363
local adminUserIds = {1055032964, 353620157}
local modUserIds = {1320435220, 1056405017}

local function IsVip(UserId : number) : boolean
	return game.ReplicatedStorage:WaitForChild("IsVip"):InvokeServer(UserId)
end

TextChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		local UserId = message.TextSource.UserId

		if UserId then

			if UserId == ownerUserId then
				properties.PrefixText = "<font color ='#42fd62'>[Owner]</font> " .. message.PrefixText

			elseif table.find(adminUserIds, UserId) then
				properties.PrefixText = "<font color ='#ffa245'>[Developer]</font> " .. message.PrefixText

			elseif table.find(modUserIds, UserId) then
				properties.PrefixText = "<font color ='#ff254d'>[Admin]</font> " .. message.PrefixText

			elseif IsVip(UserId) then
				properties.PrefixText = "<font color ='#23f4ff'>[Captain]</font> " .. message.PrefixText
			end
		end
	end

	return properties
end

Create a RemoteFunction in ReplicatedStorage and name it “IsVip”

After that, create a Script in ServerScriptService, and write this:

local MarketplaceService = game:GetService("MarketplaceService")
local VipGamepassId = 17347981

game.ReplicatedStorage.IsVip.OnServerInvoke = function(player, id)
	return MarketplaceService:UserOwnsGamePassAsync(id, VipGamepassId)
end
table.find

You can use table.find() instead of creating your own function

local function isUserInList(userId, userList)
	for _, id in pairs(userList) do
		if userId == id then
			return true
		end
	end
	return false
end
1 Like

This worked, thank you so much! I really appreciate it :pray:

1 Like